Jump to content

[SOLVED] tables


beansandsausages

Recommended Posts

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 :P:)

Link to comment
https://forums.phpfreaks.com/topic/131208-solved-tables/
Share on other sites


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> ";

}	

Link to comment
https://forums.phpfreaks.com/topic/131208-solved-tables/#findComment-681210
Share on other sites

$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> ";

Link to comment
https://forums.phpfreaks.com/topic/131208-solved-tables/#findComment-681213
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/131208-solved-tables/#findComment-681379
Share on other sites

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.