![]()
allternating color rows in a table, I know it can be done with javascript, but was wondering if all so be done in PHP, thx in advance
| SitePoint Sponsor |

![]()
allternating color rows in a table, I know it can be done with javascript, but was wondering if all so be done in PHP, thx in advance





god damn asp is ugly!PHP Code:function bgcolor()
{
global $bgcolor;
if ($bgcolor == 'white') {
$bgcolor = 'gray';
} else {
$bgcolor = 'white';
}
echo 'class="'.$bgcolor.'"';
}
while ($row = mysql_fetch_array($query))
{
echo "<tr " . bgcolor() . ">";
echo "<td> </td>";
echo "</tr>";
}
Studiotime - Time Management for Web Developers
to-do's, messages, invoicing, reporting - 30 day free trial!
Thomas Multimedia Web Development


Code:$even=true; while ($row = mysql_fetch_array($query)) { echo "<tr bgcolor=".$even?"white":"gray".">"; echo "<td> </td>"; echo "</tr>"; $even!=$even; }



Should be percent not 37.PHP Code:$i = 0;
while ($row = mysql_fetch_array($query))
{
if ($i % 2)
$bgcolor = "white";
else
$bgcolor = "gray";
echo '<tr bgcolor="'.$bgcolor.'">';
echo "<td> </td>";
echo "</tr>";
$i++;
}
I will not flame the newbies,
I will not flame the newbies,
I will flame the newbies...
Table free is the way to be!
just make a loop. Let say you're getting your stuff from database.
using while loop
PHP Code:echo "<table>";
$i=0
// this is a while loop
while () {
// if the remainder of $i divided by 2 is equals to zero
if ($i%2==0) {
echo "<tr><td></td></tr>";
} else {
echo "<tr style='background:#000;'><td></td></tr>";
}
// increases $i indicator
$i++;
}
echo "</table>";



PHP Code:$i = 0;
while ($row = mysql_fetch_array($query))
{
if ($i % 2) // i percent two
$bgcolor = "white";
else
$bgcolor = "gray";
echo '<tr bgcolor="'.$bgcolor.'">';
echo "<td> </td>";
echo "</tr>";
$i++;
}
I will not flame the newbies,
I will not flame the newbies,
I will flame the newbies...
Table free is the way to be!
Bookmarks