Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Recordset filter only odd or even numbers

New Here ,
Nov 06, 2006 Nov 06, 2006
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
TOPICS
Server side applications
418
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 07, 2006 Nov 07, 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/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 07, 2006 Nov 07, 2006
LATEST
Thank you, will try it!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines