Jump to content

Top 3 Results


Fearpig

Recommended Posts

Hi Guys,
I'm having some problems with the code below. Could someone take a look and point me in the right direction.

Basically I have a list of news articles and I want to display the top three by date in descending date order. The code below works fine untill I include the "TOP 3" part of the SQL query at which point I get the following error message:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\Intranet v3\TEST\News\Top_3_Articles.php on line 25


[code]
$result = mysql_query("SELECT TOP 3 * FROM tbl_news ORDER by Date DESC",$db);

echo "<p class='Body2'>Select news article to display...</p>";
echo "<table width=80% border=1>\n";
echo "<tr class='Body2' bgcolor=#CCCCCC><th>Date</th><th>Heading</th></tr>\n";
//colum names

while ($myrow = mysql_fetch_array($result)) {

printf("<tr><td>%s</td><td><a href=\"%s?id=%s\" class='Body2'>%s</a></td></tr>\n",
//lay out results 2 in the first column and 1 in the second
$myrow["Date"], "Result_ByArticle.php", $myrow["ID"], $myrow["Title"]);

}
echo "</table>\n";
[/code]

Any help would be appreciated as I just can't see where this is going wrong!
Link to comment
https://forums.phpfreaks.com/topic/21641-top-3-results/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.