display the mysql count function? [duplicate]
$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;
- use
$row = mysql_fetch_array($result)
and access it by index 0: $row[0] - 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
精彩评论