Jump to content

Archived

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

Fearpig

Top 3 Results

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!

Share this post


Link to post
Share on other sites
Use this instead.
$query="SELECT * FROM tbl_news ORDER by Date DESC LIMIT 0,3"
$result = mysql_query($query) or die(mysql_error());

This should bring the query out ok. I haven't looked at the rest of the code to see if that will work.

Share this post


Link to post
Share on other sites
TOP was an mssql 2005 syntax. So it wont work on mysql.

Even if there is a sql standart, most of the companies add their own features on them to be selected more. But above some expections like this, the sql syntax is the same.

Share this post


Link to post
Share on other sites

×

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.