Jump to content


Top 3 Results

  • Please log in to reply
2 replies to this topic

#1 Fearpig

  • Members
  • PipPipPip
  • Advanced Member
  • 195 posts

Posted 22 September 2006 - 09:14 AM

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

$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";

Any help would be appreciated as I just can't see where this is going wrong!
"Whats wrong with the cat?" - Mrs Schrödinger

#2 steveclondon

  • Members
  • PipPipPip
  • Advanced Member
  • 161 posts

Posted 22 September 2006 - 09:31 AM

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.

#3 radalin

  • Members
  • PipPipPip
  • Advanced Member
  • 179 posts

Posted 22 September 2006 - 11:57 AM

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.
Roy Simkes
Yet Another Parkyeri Developer

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users