0

I'm trying to limit the array mysql_fetch_assoc($query), and am unsure on how I would go about it.

$query = mysql_query('SELECT * FROM table ORDER BY id DESC');

while($output = mysql_fetch_assoc($query))
{
    //do something
}

Do you add a counter or something? How do you add this counter? I'm really confused about mysql_query and mysql_fetch_assoc. Please Help!

3 Answers 3

2

After your ORDER BY id DESC, add LIMIT 100 (or whatever number you want). For the next 100 rows, use LIMIT 100,100, then LIMIT 200,100 and so on.

Sign up to request clarification or add additional context in comments.

3 Comments

Awesoooomm!!! Thanks for the extra bit about the range of the limit. That will help me a lot!!!!!
@Kolink Isn't it LIMIT 101, 100 and LIMIT 201, 100?
Okay, havn't noticed well! :P
1

You can limit the results directly in the SQL query. To get the top 100 records do

SELECT * FROM table 
ORDER BY id DESC 
LIMIT 100

Comments

1

Use LIMIT

SELECT * FROM table ORDER BY `id` DESC LIMIT 10;

Haven't you seen phpMyAdmin always limiting to 30?

2 Comments

lol, i don't really look at what phpMyAdmin does, just make it do stuff. But thanks for the advice. I'll take more notice of such things from now on!
And yeah, for the pagination, do as Kolink said. :)

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.