Reputation: 5403
I have a database that I am successfully querying to display all rows where the value of one field equals x. What I need to do now is ONLY display the first 5 records that meet that criteria.
Here is my sql query so far:
$result = mysql_query("SELECT Player, Team, Pass_Yds, Pass_TDs, Int_Thrown, Rush_Yds, Rush_TDs, Overall_Pts, Total_Fantasy_Pts FROM ff_projections WHERE Position = 'QB' ORDER BY Pass_Yds DESC;");
I tried adding LIMIT 0,5 to the query (after DESC but before the ';') but then it wouldn't display anything at all.
Upvotes: 0
Views: 12308
Reputation: 53840
Most likely, you accidentally put in a period:
LIMIT 0.5
which amounts to:
LIMIT 0,0
or
LIMIT 0
Try putting in a comma instead like
LIMIT 0,5
or simply
LIMIT 5
Upvotes: 3
Reputation: 8012
You can use this $result = mysql_query("SELECT Player, Team, Pass_Yds, Pass_TDs, Int_Thrown, Rush_Yds, Rush_TDs, Overall_Pts, Total_Fantasy_Pts FROM ff_projections WHERE Position = 'QB' ORDER BY Pass_Yds DESC LIMIT 0,5");
Upvotes: 0