Jump to content

php and mysql (alternate row color)


ra2833

Recommended Posts

i gather information from previous threads, but i can't seem to find out what my problem is in regards to this piece of code.  can someone shed some light please?
[code]
<table width="480" border="0" cellpadding="0" cellspacing="0">
<tr class="darktable">
<td><strong>FAQ ID</strong></td>
<td><a href="sort.by.crm.case.num.php" >CRM Case #</a> </td>
<td><a href="sort.by.question.php">Question</a></td>
<td><a href="sort.by.answer.php">Answer</a></td>
<td><a href="sort.by.tech.php">Technician</a></td>
<td><a href="sort.by.site.type.php">Site Type</a></td>
<td><a href="sort.by.client_os.php">Client OS</a></td>
<td><a href="sort.by.answer.php">Application</a></td>
</tr>

<?php $style = " "; ?>
<?php $rowcolor1 = "#F0F0F2"; ?>
<?php $rowcolor2 = "#FFFFFF"; ?>

<?php $alternatecolorcounter = 0; ?>

<?php do { ?>
<?php if ($alternatecolorcounter % 2 == 1) {
$style = $rowcolor1;
} else {
$style = $rowcolor2;
} ?>
<tr>
<td style="background:'.$style.'"><?php echo $row_faq_all['faq_unique_id']; ?></td?
</tr>
<?php $alternatecolorcounter++ ?>
<?php } while ($row_faq_all = mysql_fetch_assoc($faq_all) && $alternatecolorcounter <= $totalRows_faq_all); ?>
</table>[/code]
Link to comment
https://forums.phpfreaks.com/topic/34821-php-and-mysql-alternate-row-color/
Share on other sites

thanks man, that was soooo freaking quick (awesome)....

here is what i ended up with
[code]
<?php
$style = "";

$rowcolor1 = "#8A3324";
$rowcolor2 = "#00B2EE";

$alternatecolorcounter = 0;

do {
if ($alternatecolorcounter % 2 == 1) {
$style = $rowcolor1;
} else {
$style = $rowcolor2;
}

echo "\t<tr bgcolor=\"$style\">\n".
"\t\t<td>". $row_faq_all['faq_unique_id'] ."</td>\n".
"\t\t<td>". $row_faq_all['crm_case_num'] ."</td>\n".
"\t\t<td>". $row_faq_all['question'] ."</td>\n".
"\t\t<td>". $row_faq_all['answer'] ."</td>\n".
"\t\t<td>". $row_faq_all['tech'] ."</td>\n".
"\t\t<td>". $row_faq_all['site_type'] ."</td>\n".
"\t\t<td>". $row_faq_all['client_os'] ."</td>\n".
"\t\t<td>". $row_faq_all['application'] ."</td>\n".
            "\t</tr>\n";

$alternatecolorcounter++;
} while ($row_faq_all = mysql_fetch_assoc($faq_all));
?>
[/code]

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.