This topic is locked

Limit SQL Query Result

7/24/2008 9:26:58 PM
PHPRunner General questions
A
allan author

Hi, I would like to limit the query result to the first 10 so that I can make a top 10 graph. I have been using this

SELECT

UserID,

Username,

Status,

Total

FROM user

WHERE Status ='Approved'

ORDER BY `Total` DESC, Username

LIMIT 0,10


but it says syntax error. I have tried LIMIT `0, 10`, LIMIT "0, 10" still syntax error.
I have found this http://www.asprunner.com/forums/index.php?...91&hl=LIMIT which is what I want to achieve but I couldn't understand the workaround.
If I edited the `user` table query from phpmyadmin, does that mean the list view will only list top 10 entries? And if I am to create another table using the same query as in `user` table, eg. `top 10 user` but add in the limit, that will result in 2 similar table and how do I sync both of them?
I am very new to both mysql and php, I apologize if the question doesn't make sense.
Thanks

J
Jane 7/25/2008

Hi,
you don't need to edit main table in the database.

Just create view of this table:

create view `viewname` as

SELECT

UserID,

Username,

Status,

Total

FROM user

WHERE Status ='Approved'

ORDER BY `Total` DESC, Username

LIMIT 0,10



And then create chart in the PHPRunner based on this view.

A
allan author 7/25/2008

I got it working. Thank you