Jump to content

Double column and alternating rows


lu13cky
 Share

Recommended Posts

I'm attempting to do a table with two columns that displays information from one database and that also has alternating row colors.this is what I have so far:

$result = mysql_query("SELECT * FROM table WHERE ID = '$id' ORDER BY name ASC") or die('Could not run query because: '.mysql_error());$count = 2;while ($row = mysql_fetch_assoc($result)) {$rowcolor = rowcolor($count);$tableborder = tableborder($count);$id = $row['id'];$name = $row['name'];$info = $row['info'];$infoii = $row['infoii'];$url = $row['url'];$contact = $row['contact'];if ($count%2) { ?><td><div class="name">  <? echo $name; ?></div><div class="info"><? echo $info; ?> and <? echo $infoii; ?><br /><? echo $url; ?></div><div class="contact"><? echo $contact ?></div></td></tr></table><br /> <? }else { ?><table class="<? echo $tableborder; ?>" width="95%" cellpadding="0" cellspacing="0"><tr class="<? echo $rowcolor; ?>"><td><div class="name">  <? echo $name; ?></div><div class="info"><? echo $info; ?> and <? echo $infoii; ?><br /><? echo $url; ?></div><div class="contact"><? echo $contact ?></div></td>  <? }$count++;}?></table>

and in my header I currently have:

<?phpfunction rowcolor($count){  $nr = ($count % 2) + 1;  return 'row-' . $nr;} ?> <?phpfunction tableborder($count){  $nr = ($count % 2) + 1;  return 'table-' . $nr;} ?>

Now I can get it to display two columns, but it obviously loses the alternating colors. And I can bring them back if I set the count to 3...but that isn't really a problem solver as it does not provide alternating colors for every other row. Any help would be appreciated! Thanks

Link to comment
Share on other sites

I'm confused about your if statement, why do you output different data based on the count? For one database record you output the first cell, and then for the next record you output the second cell, then the next record the first cell, etc. Why not output both cells for every record?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...