Since I'm trying to count the number of records in a table, even if the SQL statement has a LIMIT in it, in general it works, however, something strange happens, the code:
$sql = "SELECT COUNT(*) AS count FROM posts ORDER BY post_date DESC LIMIT 5"; // ... mysql_query, etc while($row = mysql_fetch_array($result)) { // ... HTML elements, etc echo $row['post_title']; // ... HTML elements, etc echo $row['count']; // this displays the number of posts (which shows "12"). }
Although when displayed through a while it displays this:
Note: Undefined index: post_title in /Applications/MAMP/htdocs/blog/index.php on line 55
If I delete COUNT(*) AS count , everything will display fine ... how is this done?
php mysql count while-loop
Macmac
source share