how to count the total comment

前端 未结 1 1713
忘了有多久
忘了有多久 2021-01-26 12:13

I want to count the total comment/post posted on my page. i have a table in my database named test. within table i have a column named comment, where every post is been stored.

相关标签:
1条回答
  • 2021-01-26 12:46

    Try this:

    list($count) = mysql_fetch_row(mysql_query("select count(*) from `test`"));
    echo $count;
    

    Alternatively, if you are already running a query to get some comments, you can try this:

    $sql = mysql_query("select sql_calc_found_rows * from `test` order by `id` desc limit 10");
    // ^ Get the 10 most recent comments
    list($count) = mysql_fetch_row(mysql_query("select found_rows()"));
    // this avoids having to run the entire query again, great for efficiency!
    while($comment = mysql_fetch_assoc($sql)) var_dump($comment); // just an example
    
    0 讨论(0)
提交回复
热议问题