Im making a table that wil grab all info from the database and display it, but how do i make it so everyother table row display, it wont be white, but like grey?
another easy question
anyone?
don't double post.... we'll get around to seeing your question....
Now, what you do is a quick switch:
// You do your query and hold results in $result variable
$color1 = '#fff';
$color2 = '#ccc';
$i=1;
while($row = mysql_fetch_array($result))
{
// Define color:
$color = ($i%2==0)?$color1:$color2;
echo '<td style="background-color: '.$color.';">';
// Display your data.....
}
Or you could make some sort of screen overlay from acetate and felt tips. Create a number and you can vary the mood a little. They sell them commercially as "Cellulose Screen Sheathes" or CSS for short.
ok, like BP ur the best, but i tried adding it and i get errors, or only 1 table appears, so how owuld i input it to
<html>
<head>
<basefont face="Arial">
</head>
<body>
<?php
// set server access variables
$host = "db301.perfora.net";
$user = "dbo155804794";
// open connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
// create query
$query = "SELECT * FROM games ORDER by id DESC LIMIT 6";
// execute query
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
// see if any rows were returned
if (mysql_num_rows($result) > 0) {
// yes
// print them one after another
echo "<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
while(list($id, $title, $picturepath, $console, $text, $genre) = mysql_fetch_row($result)) {
echo "<tr>";
echo "<td width='3%' bgcolor='#464646' align='center' valign='middle'><img src='$picturepath'/></td>";
echo "<td width='1%' bgcolor='#464646' > </td>";
echo "<td width='96%' bgcolor='#464646' valign='top'><strong>";
echo "<font size=5 color=#79CEF7>$title</font></strong> <font color=#ffffff>($console)</font>";
echo "<br /><font color='#FFFFFF'>$text<br /></font>";
echo "<font size=2 color= #79CEF7>Genre: $genre</font> </td>";
echo "</tr>";
echo "<tr>";
echo "<td align='center' valign='middle' bgcolor='#FFFFFF'></td>";
echo "<td bgcolor='#FFFFFF'><font size=1></font></td>";
echo "<td valign='top' bgcolor='#FFFFFF'></td>";
echo "</tr>";
}
echo "</table>";
}
else {
// no
// print status message
echo "No rows found!";
}
// free result set memory
mysql_free_result($result);
// close connection
mysql_close($connection);
?>
</body>
</html>
if (mysql_num_rows($result) > 0) {
// yes
// print them one after another
// MY EDIT!!
$i=1;
$color1 = '#464646';
$color2 = '#fefefe';
/*********/
echo "<table width='100%' border='0' cellspacing='0' cellpadding='0'>";
while(list($id, $title, $picturepath, $console, $text, $genre) = mysql_fetch_row($result)) {
// MY EDIT!!
$color = ($i%2==0)?$color1:$color2;
// Use this on the row, and remove the column colorings....
/*********/
echo "<tr bgcolor='$color'>";
echo "<td width='3%' align='center' valign='middle'><img src='$picturepath'/></td>";
echo "<td width='1%'> </td>";
echo "<td width='96%' valign='top'><strong>";
echo "<font size=5 color=#79CEF7>$title</font></strong> <font color=#ffffff>($console)</font>";
echo "<br /><font color='#FFFFFF'>$text<br /></font>";
echo "<font size=2 color= #79CEF7>Genre: $genre</font> </td>";
echo "</tr>";
// MY EDIT!!
$i++;
$color = ($i%2==0)?$color1:$color2;
/*********/
echo "<tr bgcolor='$color'>";
echo "<td align='center' valign='middle'></td>";
echo "<td bgcolor='#FFFFFF'><font size=1></font></td>";
echo "<td valign='top'></td>";
echo "</tr>";
// MY EDIT!!
$i++;
/*********/
}
echo "</table>";
Something like that.....
THANKS, you like constantly help me!