lu13cky Posted March 31, 2010 Share Posted March 31, 2010 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 More sharing options...
justsomeguy Posted March 31, 2010 Share Posted March 31, 2010 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.