COUNT(*)中的PHP错误为num

时间:2012-06-30 02:34:21

标签: php mysql

我收到错误Notice: Use of undefined constant num - assumed 'num'我的代码正在关注

$query = "SELECT COUNT(*) AS num FROM $tableName";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages[num];

如何解决这个问题?

我没有得到合适的头衔,所以请不要将其改为适合

3 个答案:

答案 0 :(得分:4)

@AkhileshBChandran给出了一个正确的解决方案。将来,如果您要引用该列,则需要将其放在引号中。

$total_pages = $total_pages['num'];

答案 1 :(得分:1)

$total_pages = $total_pages[0];

答案 2 :(得分:0)

$total_pages = $total_pages['num'];