Get data from database and display with odd or even id number

I have a table with set of information. I set the id for each row (in about 30 rows of info). Is there any way that I can tell PHP to get only the odd or even id number to display on the web page?

I want to display them in two columns: rows with an odd id on the left, and those with an even id on the right.

How would that code be written? Or.. can anyone tell me some sources or tutorials to read?

-------------Problems Reply------------

Use MODULO to check whether value is odd/even check here for more information

so :

if ($counter % 2) {
// ODD RESULTS
} else {
// EVEN RESULTS
}

$id % 2 == 0 //is even

$id % 2 == 1 //is odd

This is a fairly standard pattern.

Since you're iterating through your results in sequential order, and since tables are built in horizontal order, your pseudo-code looks like this:

<table>
<tr>
FOREACH RESULT i
<td>DATA(i)</td>
IF i IS ODD
</tr><tr>
ENDIF
ENDFOREACH
</tr>
</table>

Ideally you would add more conditionals to avoid empty rows, but this ought to get you started.

Might be simpler to pull everything in your query, add a css class to each row (either odd or even) and then use a very simple jquery command to display the ones you want

$(document).ready(function () {
$('.odd').display( etc....

Something like that...

Category:php Views:0 Time:2011-08-10
Tags: php

Related post

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.156 (s). 11 q(s)