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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.