Jump to content

[SOLVED] while fetch_assoc: only every second result


php_guest

Recommended Posts

I would like to display results on table like in the image.

 

The problems are two: First 5 results are displayed in column with different background color, another 5 results with another and another 5 results with another. And each second row of each column has white background.

 

So if I choose while ($row=mysql_fetch_assoc($result2)), how I can pick up every second results to display them with different style and again 5 results, than 5-10 and then 10-15?

 

Does mysql_fetch_assoc give any option to say something like mysql_fetch_assoc...if row is 1-5 {do this} elseif row is 10-15, ...?

 

Thank you

 

table.png

You probably use while loop in PHP to lop through the results. Create a variable that will increment on each pass of the loop.

 

$rowCounter = 0;
while($row = mysql_fetch_assoc($result)) {
  $rowCounter++;
  if(($rowCounter % 2) == 0) {
    //style for even rows
  } else {
    //style for odd rows
  }
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.