简体   繁体   中英

display the mysql count function?

$query = "select count(*)
                      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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM