Counting MySQL records with a LIMIT

As I am trying to count the number of records in a table, even when the SQL statement has a LIMIT into it, overall it works, however something weird 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 displaying through the while loop, it displays this:

Notice: Undefined index: post_title in /Applications/MAMP/htdocs/blog/index.php on line 55

If I remove the COUNT(*) AS count, everything will display perfectly... how come it's doing this?

6
задан MacMac 7 February 2011 в 19:24
поделиться