开发者

display the mysql count function? [duplicate]

开发者 https://www.devze.com 2023-01-17 18:55 出处:网络
This question already has answers here: SELECT COUNT(*) AS count - How to use this count (5 answers) Closed 1 year ago.
This question already has answers here: SELECT COUNT(*) AS count - How to use this count (5 answers) Closed 1 year ago.
$query = "select count(*)
         开发者_JS百科             from relationships
                      where leader = 'user_id'";
            $result = mysql_query($query);

how can i display the count? thanks


$count = mysql_fetch_array($result);
echo $count[0];


$query = "SELECT COUNT(*) AS total FROM table"; 
$result = mysql_query($query); 
$values = mysql_fetch_assoc($result); 
$num_rows = $values['total']; 
echo $num_rows;


  1. use $row = mysql_fetch_array($result) and access it by index 0: $row[0]
  2. use an alias in your query ("select count(*) as cnt from ...") and $row = mysql_fetch_assoc($result) and access it by name: $row['cnt']


$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'];
  }     

}

Its work completely in this it count the number of occurrences of 4 in the column

0

精彩评论

暂无评论...
验证码 换一张
取 消