Dada78 Posted January 22, 2008 Share Posted January 22, 2008 Ok this is the last thing I need to adjust on this page and it will be done. I am trying to have it where each td class on each row is a different color like I had it before instead of just one color all the way down like it is now. I am stuck on how to finish this. I have done this before but I have forgot how I did it and this is as much of the code as I could remember. You can see the page I am talking about. You will notice the rows are all one color. Well the classes are set by td column not by row because of style information. http://mesquitechristmas.com/local/browse.php Here is the code I am working with <?php include ('db_connect.php'); function show_data(){ $id = array(); $imgurl = array(); $address = array(); $city = array(); $state = array(); $postal = array(); $country = array(); $id = mysql_real_escape_string($_GET['id']); $i=0; if (isset($id)) { $sql = "SELECT * FROM users"; if($result = mysql_query($sql)) { $color1 = '#DDDDDD'; $color2 = '#EEEEEE'; $i = 0; while ($row = mysql_fetch_array ($result)) { $color = (($i%2 == 0 || $i == 0) ? $color1 : $color2); $id[$i] = $row["id"]; $imgurl[$i] = $row["imgurl"]; $address[$i] = $row["address"]; $city[$i] = $row["city"]; $state[$i] = $row["state"]; $postal[$i] = $row["postal"]; $country[$i] = $row["country"]; print"<tr><td class='bg2'width=110><a href='/local/display.php?id= $id[$i]'><img src='$imgurl[$i]' class='border' height'75' width='100'></a></td><td class='bg2'>$address[$i]<br>$city[$i] $state[$i] $postal[$i]<br>$country[$i]</td><td class='bg2' style='vertical-align: middle'>> <a href='display.php?id=$id[$i]'><b>Learn more about Display</b></a><br><br>> <a href='http://www.mapquest.com/maps/map.adp?searchtype=address&formtype=search&countryid=US&addtohistory=&country=US&address=$address[$i]&city=$city[$i]&zipcode=$postal[$i]&historyid=&submit=Get+Map' target='BLANK'><b>Get Directions</b></a></td></tr>"; ++$i; } } } } ?> Can someone help me out with this or maybe know of an easier way to do this or know how to get this done? -Thanks Link to comment https://forums.phpfreaks.com/topic/87155-solved-alternating-colors-on-database-output/ Share on other sites More sharing options...
teng84 Posted January 22, 2008 Share Posted January 22, 2008 <?php include ('db_connect.php'); function show_data(){ $id = array(); $imgurl = array(); $address = array(); $city = array(); $state = array(); $postal = array(); $country = array(); $id = mysql_real_escape_string($_GET['id']); $i=0; if(isset($id)) { $sql = "SELECT * FROM users"; if($result = mysql_query($sql)) { $i = 0; while ($row = mysql_fetch_array ($result)) { $color = ($i%2== 0 || $i == 0)?'#DDDDDD':'#EEEEEE'; $id[$i] = $row["id"]; $imgurl[$i] = $row["imgurl"]; $address[$i] = $row["address"]; $city[$i] = $row["city"]; $state[$i] = $row["state"]; $postal[$i] = $row["postal"]; $country[$i] = $row["country"]; print"<tr><td class='bg2'width=110><a href='/local/display.php?id= $id[$i]'><img src='$imgurl[$i]' class='border' height'75' width='100'></a></td><td class='bg2'>$address[$i]<br>$city[$i] $state[$i] $postal[$i]<br>$country[$i]</td><td class='bg2' style='vertical-align: middle'>> <a href='display.php?id=$id[$i]'><b>Learn more about Display</b></a><br><br>> <a href='http://www.mapquest.com/maps/map.adp?searchtype=address&formtype=search&countryid=US&addtohistory=&country=US&address=$address[$i]&city=$city[$i]&zipcode=$postal[$i]&historyid=&submit=Get+Map' target='BLANK'> <b>Get Directions</b></a></td></tr>"; ++$i; } } } } ?> try Link to comment https://forums.phpfreaks.com/topic/87155-solved-alternating-colors-on-database-output/#findComment-445778 Share on other sites More sharing options...
Dada78 Posted January 22, 2008 Author Share Posted January 22, 2008 Thanks for the reply. I tried that but it didn't work. If you notice in the print statement it has this td class='bg2' so what would I need to replace there? Would it be this instead of class? $color[$i] -Thanks Link to comment https://forums.phpfreaks.com/topic/87155-solved-alternating-colors-on-database-output/#findComment-445781 Share on other sites More sharing options...
teng84 Posted January 22, 2008 Share Posted January 22, 2008 <?php include ('db_connect.php'); function show_data(){ $id = array(); $imgurl = array(); $address = array(); $city = array(); $state = array(); $postal = array(); $country = array(); $id = mysql_real_escape_string($_GET['id']); $i=0; if(isset($id)) { $sql = "SELECT * FROM users"; if($result = mysql_query($sql)) { $i = 0; while ($row = mysql_fetch_array ($result)) { $color = ($i%2== 0 || $i == 0)?'#DDDDDD':'#EEEEEE'; $id[$i] = $row["id"]; $imgurl[$i] = $row["imgurl"]; $address[$i] = $row["address"]; $city[$i] = $row["city"]; $state[$i] = $row["state"]; $postal[$i] = $row["postal"]; $country[$i] = $row["country"]; print"<tr> <td bgcolor='".$color."'width=110> <a href='/local/display.php?id= $id[$i]'> <img src='$imgurl[$i]' class='border' height'75' width='100'> </a> </td> <td bgcolor='".$color."'>$address[$i]<br>$city[$i] $state[$i] $postal[$i]<br>$country[$i]</td> <td bgcolor='".$color."' style='vertical-align: middle'>> <a href='display.php?id=$id[$i]'><b>Learn more about Display</b></a><br><br>> <a href='http://www.mapquest.com/maps/map.adp?searchtype=address&formtype=search&countryid=US&addtohistory=&country=US&address=$address[$i]&city=$city[$i]&zipcode=$postal[$i]&historyid=&submit=Get+Map' target='BLANK'> <b>Get Directions</b> </a> </td> </tr>"; ++$i; } } } } ?> try Link to comment https://forums.phpfreaks.com/topic/87155-solved-alternating-colors-on-database-output/#findComment-445785 Share on other sites More sharing options...
Dada78 Posted January 22, 2008 Author Share Posted January 22, 2008 Thanks that did the trick. Thank you for your help. Link to comment https://forums.phpfreaks.com/topic/87155-solved-alternating-colors-on-database-output/#findComment-445788 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.