Fearpig Posted September 22, 2006 Share Posted September 22, 2006 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 nameswhile ($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! Quote Link to comment Share on other sites More sharing options...
steveclondon Posted September 22, 2006 Share Posted September 22, 2006 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. Quote Link to comment Share on other sites More sharing options...
radalin Posted September 22, 2006 Share Posted September 22, 2006 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.