Answers:
您需要使用as
关键字为聚合设置别名,以便从中进行调用mysql_fetch_assoc
$result=mysql_query("SELECT count(*) as total from Students");
$data=mysql_fetch_assoc($result);
echo $data['total'];
如果只需要该值:
$result = mysql_query("SELECT count(*) from Students;");
echo mysql_result($result, 0);
echo mysql_result(mysql_query("SELECT count(*) from Students;"),0);
正在保存一个不必要的变量
这是使用PHP在表格中不显示行的代码
$sql="select count(*) as total from student_table";
$result=mysqli_query($con,$sql);
$data=mysqli_fetch_assoc($result);
echo $data['total'];
AS
这里使用,而不需要输入echo $data['count(*)'];
对于mysqli用户,代码将如下所示:
$mysqli = new mysqli($db_host, $db_user, $db_pass, $db_name);
$result = $mysqli->query("SELECT COUNT(*) AS Students_count FROM Students")->fetch_array();
var_dump($result['Students_count']);
要么:
$mysqli = new mysqli($db_host, $db_user, $db_pass, $db_name);
$result = $mysqli->query("SELECT COUNT(*) FROM Students")->fetch_array();
var_dump($result[0]);
$howmanyuser_query=$conn->query('SELECT COUNT(uno) FROM userentry;');
$howmanyuser=$howmanyuser_query->fetch_array(MYSQLI_NUM);
echo $howmanyuser[0];
经过这么多小时的出色:)
$abc="SELECT count(*) as c FROM output WHERE question1=4";
$result=mysqli_query($conn,$abc);
if($result)
{
while($row=mysqli_fetch_assoc($result))
{
echo $row['c'];
}
}
在此计数它在question1栏中出现的次数,其工作完全
使用mysql v5.7.20,这就是我如何使用PHP v7.0.22从表中获取行数的方法:
$query = "select count(*) from bigtable";
$qresult = mysqli_query($this->conn, $query);
$row = mysqli_fetch_assoc($qresult);
$count = $row["count(*)"];
echo $count;
第三行将返回如下结构:
array(1) {
["count(*)"]=>string(4) "1570"
}
在这种情况下,结尾的echo语句将返回:
1570
您需要使用as
关键字为聚合设置别名,以便从中进行调用mysqli_fetch_assoc
$result=mysqli_query($conn,"SELECT count(*) as total from Students");
$data=mysqli_fetch_assoc($result);
echo $data['total'];
$db = new PDO('mysql:host=localhost;dbname=java_db', 'root', '') or die(mysql_errno());
$Sql = "SELECT count(*) as 'total' FROM users";
$stmt = $db->query($Sql);
$stmt->execute();
$data = array();
$total = $stmt->fetch(PDO::FETCH_ASSOC);
print '<pre>';
print_r($total);
print '</pre>';
结果:
我认为这是更好的答案。
$query = "SELECT count(*) AS total FROM table_name";
mysql_select_db('database_name');
$result = mysql_query($query);
$values = mysql_fetch_assoc($result);
$num_rows = $values['total'];
echo $num_rows;
$qry_appr = "SELECT COUNT(*) FROM comments WHERE admin_panel_id ='$id' AND status = 'ON'";
$qry_data = mysqli_query($con, $qry_appr);
$approve_count = mysqli_fetch_array($qry_data);
$toatalCount = array_shift($approve_count);
echo $toatalCount;
这也可以,但是可以通过移动获取数组来返回0索引值。欢迎大家
在选项范围之外,没有提到这一选项。即使它不是最佳的或不必要的,也可以通过一个简单的循环来完成:
$result=mysqli_query($conn, "SELECT count(1) as total from Students");
foreach ($result as $rez) {$numb=$rez['total'];}
echo $numb;
mysql_
函数-即使这个老问题正在使用它。在我的IDE中,会有一个标志说明$numb
可能未声明。PushkarPokharkar已经完成了使用循环的操作,但同样没有必要。我将尽我所能,通过降低我不推荐使用的技术来帮助研究人员。