NYCPHP Meetup

NYPHP.org

[nycphp-talk] every other record

Chris Merlo chris at theyellowbox.com
Wed Feb 1 15:19:47 EST 2006


On 2/1/06, Rahmin Pavlovic <rahmin at insite-out.com> wrote:
>
> To the more knowledgeable SQL heads in the house:
>
> Do you think it's reliable to mod() the record id to pull every other
> record, like:
>
> select * from table where mod(id,2)=0 #or
> select * from table where mod(id,2)=1


Off the top of my head, I can think of a scenario where this will not work.
If you have a table with an auto-generated ID, where you have ever deleted a
record, in my experience with MySQL, the deleted ID won't get reused, and so
your ID values will be 1, 2, 3, 5, 6, 7, etc...  Therefore, that first line
will grab records with IDs 1, 3, 6, 8, etc...  I would probably write
something in PHP to grab *all* the records, and then play with every other
one.
-c

--
chris at theyellowbox.com
http://www.theyellowbox.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20060201/0680e202/attachment.html>


More information about the talk mailing list