Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
261 views
in Technique[技术] by (71.8m points)

MySQL and PHP - how to display only the first five rows?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...