0

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.

2
  • 1
    Seems like adding limit should work. What happens if you add limit and run the query directly against the server? Commented May 30, 2012 at 13:23
  • 4
    This should work 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 5;, run this query in phpadmin and check results Commented May 30, 2012 at 13:24

2 Answers 2

3

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
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.