mysql_num_rows always returns 1

前端 未结 4 385
小蘑菇
小蘑菇 2020-11-30 15:45

The result is always 1:

$sql = \'SELECT COUNT(Vote) FROM \' . $table;
$res = mysql_query($sql, $conn);
$vote_total = mysql_num_rows($res);

4条回答
  •  长情又很酷
    2020-11-30 15:59

    There will only ever be one row. And in that row will be the count of votes.

    $sql = 'SELECT COUNT(Vote) FROM ' . $table;
    $res = mysql_query($sql, $conn);
    $vote_array = mysql_fetch_array($res);
    $vote_total = $vote_array[0];
    

    If you want to count the number of votes with mysql_num_rows, you have to select ALL of the rows.

提交回复
热议问题