views:

31

answers:

3
$query = "select count(*)
                      from relationships
                      where leader = 'user_id'";
            $result = mysql_query($query);

how can i display the count? thanks

+1  A: 
$count = mysql_fetch_array($result);
echo $count[0];
captaintokyo
A: 
$query = "SELECT COUNT(*) AS total FROM table"; 
$result = mysql_query($query); 
$values = mysql_fetch_assoc($result); 
$num_rows = $values['total']; 
echo $num_rows;
sushil bharwani
A: 
  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']
hacksteak25