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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.