Alternate Rows

O

old.Mozzer

Guest
Anyone have an idea how to alternate the colours of the rows from a database?

ta!
 
B

Bazerka

Guest
PHP:
$link = mysql_connect("host","login","password");

mysql_select_db("my_database");

$query = "SELECT * FROM my_table";
$result = mysql_query($query);

$rowcolor1 = "#FF0000";
$rowcolor2 = "#00FF00";

echo "<table>";

while($line = mysql_fetch_array($result)) {

  $rowcolor = ($rowcolor == $rowcolor1) ? $rowcolor2 : $rowcolor1; 

  echo "<tr bgcolor=$rowcolor>";
  echo "  <td>$line["field1"]</td>";
  echo "  <td>$line["field2"]</td>";
  echo "</tr>"
}

echo "</table>";
mysql_close($link);

Something along those lines should do the trick. :clap:

Jase.
 
T

Teaser

Guest
Or...

/* All the database stuff */

$x = 0 ;
while ( there are rows )
{
$rowcolor = ( (x^1) > x ) ? $rowcolor = "#123456" : $rowcolor = "#789010" ;

echo "<td bgcolor = $rowcolor>Some stuff</td>" ;

$x++ ;
}
 

Users who are viewing this thread

Top Bottom