计算一行并在td中显示它

时间:2022-10-06 15:30:14

I need to count number of name in a table like this:

我需要计算一个表中的名称数量,如下所示:

<td>
<?php 
$count_name="SELECT count(name) AS Total FROM users WHERE name=".$rows['name'];
$count_res=mysqli_query($con, $count_name);
$count = mysqli_fetch_array($count_res);
print_r($count);
?>
</td>

Where $rows['name'] is a result of another working query. I tried everything but I always get errors so any help with it ?

$ rows ['name']是另一个工作查询的结果。我尝试了一切,但我总是得到错误,所以任何帮助吗?

1 个解决方案

#1


1  

name is string . you have use it inside ''

name是字符串。你在里面用它''

try like this

试试这样

name='".$rows['name']."'"

Full form

$count_name="SELECT count(name) AS Total FROM users WHERE name='".$rows['name']."'";

EDIT

I got this: Array ( [0] => 1 [Total] => 1 ) But I need To see only Total = 1 without Array([0]

我得到了这个:数组([0] => 1 [总] => 1)但是我需要只看到没有数组的总数= 1([0]

Just print via column name

只需通过列名打印即可

like this

echo $count["Total"];

#1


1  

name is string . you have use it inside ''

name是字符串。你在里面用它''

try like this

试试这样

name='".$rows['name']."'"

Full form

$count_name="SELECT count(name) AS Total FROM users WHERE name='".$rows['name']."'";

EDIT

I got this: Array ( [0] => 1 [Total] => 1 ) But I need To see only Total = 1 without Array([0]

我得到了这个:数组([0] => 1 [总] => 1)但是我需要只看到没有数组的总数= 1([0]

Just print via column name

只需通过列名打印即可

like this

echo $count["Total"];