Jump to content

Archived

This topic is now archived and is closed to further replies.

CanMan2004

Ignoring a selected amount of rows

Recommended Posts

Hi all

Is there a way to put something into a query which ignores the first defined number of results.

For example, if I have the following query

[code]SELECT * FROM mydata WHERE `name` = '".$name."' AND allowed = 'YES' ORDER BY `idnum` DESC LIMIT 20[/code]

Is there a way to ignore the first x number of results which are returned.

x is a number, so if your results brought back id numbers

1
2
3
4
5
6

and you said for it to ignore the first 4, then it would return

5
6

Can this be done?

Thanks in advance

Ed

Share this post


Link to post
Share on other sites
I think that was done with arrays() but a real good intresting quistion, Will be nice to see that done with the database.

Share this post


Link to post
Share on other sites
Yeah, you provide LIMIT with two arguments

[color=green][b]LIMIT 4, 20[/b][/color]

The first is the offset you want and the second is the amount of rows to return.

It returns rows based on the offset of your dataset, not the entire table.  So if you had the following data:

ID, Name
1    Rich
2    Paul
3    Sam
4    Ryan
5    Dave

[color=maroon]SELECT name FROM table ORDER BY id LIMIT 1, 1[/color] you'd get Paul, but if you had SELECT name FROM table WHERE name LIKE 'R%' ORDER BY name LIMIT 1, 1 then you'd get Ryan.

I hope that makes sense

Regards
Huggie

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.