Skip to main content
Participant
November 7, 2006
Question

Recordset filter only odd or even numbers

  • November 7, 2006
  • 2 replies
  • 426 views
Hello

Using php environment, I wish to make two dynamic tables side by side on the same page, but I want one to only show a recordset with odd row entries from a mySQL database table, while the other shows the even entries from a mySQL database table.

for example - the first one would only filter id_article =1, 3, 5 etc...
while the second would only fitler id_article =2,4,6 etc...

Therefore, what should I write in the recordset window under filter?
id_article = ?

Thank you :D
This topic is closed to new replies. Start a new post to keep the conversation going.

2 replies

haigotronAuthor
Participant
November 7, 2006
Thank you, will try it!
Inspiring
November 7, 2006
haigotron wrote:
> for example - the first one would only filter id_article =1, 3, 5 etc...
> while the second would only fitler id_article =2,4,6
> etc...
>
> Therefore, what should I write in the recordset window under filter?
> id_article = ?

You can't do it in the simple recordset dialog box. Click the Advanced
button and amend the SQL like this to select odd numbers:

SELECT * FROM myTable
WHERE article_id%2 = 1

To select even numbers:

SELECT * FROM myTable
WHERE article_id%2 = 0

This uses the modulo operator (%) to divide the article_id by 2. Modulo
gives you the remainder of a division, so if the remainder is 1, you
know the number is odd.

You should realize that this works on the records' primary key. Once you
start deleting records from your database, gaps will appear in the
sequence. You would need to take a different approach to sort odd and
even *results*.

--
David Powers
Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
http://foundationphp.com/