Jump to content


Photo

Ignoring a selected amount of rows


  • Please log in to reply
3 replies to this topic

#1 CanMan2004

CanMan2004
  • Members
  • PipPipPip
  • Advanced Member
  • 254 posts

Posted 20 September 2006 - 07:01 PM

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

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

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

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 20 September 2006 - 07:05 PM

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

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 20 September 2006 - 07:07 PM

Yeah, you provide LIMIT with two arguments

LIMIT 4, 20

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

SELECT name FROM table ORDER BY id LIMIT 1, 1 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
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#4 CanMan2004

CanMan2004
  • Members
  • PipPipPip
  • Advanced Member
  • 254 posts

Posted 20 September 2006 - 11:23 PM

thank you




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users