beansandsausages Posted November 3, 2008 Share Posted November 3, 2008 Howdy!! I can't really decide if this is a PHP Problem or HTML ??? ??? So i just posted it in here. I have a mysql array that returns results from a data base. I want to put thm in a table i can do this bit. But how would i get the table <td> colors to show two (2) diffrent colors? Like the replies on here. They go White then Blue then White etc ... ... Any way sorry if its in wrong bored Quote Link to comment Share on other sites More sharing options...
F1Fan Posted November 3, 2008 Share Posted November 3, 2008 Create a variable with "on" and "off" states. Then just toggle it for each row and use that var to determine which color to use. Quote Link to comment Share on other sites More sharing options...
beansandsausages Posted November 3, 2008 Author Share Posted November 3, 2008 Create a variable with "on" and "off" states. Then just toggle it for each row and use that var to determine which color to use. that means ill have to add a new record the the database though. Quote Link to comment Share on other sites More sharing options...
F1Fan Posted November 3, 2008 Share Posted November 3, 2008 No. Display you're code and I'll show you how. Quote Link to comment Share on other sites More sharing options...
beansandsausages Posted November 3, 2008 Author Share Posted November 3, 2008 if($_GET['mod'] == "view" ) { if (!mysql_select_db("blog")) { echo "Unable to select mydbname: " . mysql_error(); exit; } $sql = "SELECT * FROM `accounts` WHERE `access` = 1 "; $result = mysql_query($sql); if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "<h1>Sorry there is no accounts to see. </h1><br />"; } $record = mysql_num_rows($result); echo " <h1>There is a total of <strong>{$record}</strong> accounts you may see.</h1>"; echo " <table> <tr><td width=\"25%\">Account ID </td> <td width=\"25%\"> Account Name </td> </tr> "; while ($a = mysql_fetch_assoc($result)) { echo " <tr><td width=\"25%\">{$a['id']} </td> <td width=\"25%\"> {$a['name']} </td></tr>"; } echo " </table> "; } Quote Link to comment Share on other sites More sharing options...
F1Fan Posted November 3, 2008 Share Posted November 3, 2008 $bgcolor = "C0C0C0"; echo " <table> <tr><td width=\"25%\">Account ID </td> <td width=\"25%\"> Account Name </td> </tr> "; while ($a = mysql_fetch_assoc($result)) { $bgcolor = $bgcolor=="C0C0C0"?"FFFFFF":"C0C0C0"; echo " <tr><td bgcolor=\"#$bgcolor\" width=\"25%\">{$a['id']} </td> <td bgcolor=\"#$bgcolor\" width=\"25%\"> {$a['name']} </td></tr>"; } echo " </table> "; Quote Link to comment Share on other sites More sharing options...
beansandsausages Posted November 3, 2008 Author Share Posted November 3, 2008 You my friend are a genius haha thank you. Quote Link to comment Share on other sites More sharing options...
Yesideez Posted November 3, 2008 Share Posted November 3, 2008 If you've got two CSS styles you can also do it something like this: <?php $rowCounter=0; while ($a=mysql_fetch_assoc($query)) { $rowCounter++; echo '<tr class="style'.($rowCounter % 2 'dark' : 'light').'"><td>'.$a['id'].'</td><td>'.$a['name'].'</td></tr>'; } This is presuming you've got two styles set up something like this: .styledark {background-color: #88ffff;} .stylelight {background-color: #ccffff;} Would definitely need Quote Link to comment Share on other sites More sharing options...
Yesideez Posted November 3, 2008 Share Posted November 3, 2008 btw, I removed the width="25%" bit because you're declaring two data cells per row supplying a total of only 50%. If specifying widths in percentages try and make them all add to 100%. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.