Forums
This topic is locked
Row numbers in MySQL dataset
09 Feb 2005 09:56:38 K Orian posted:
I want to change the row background color for alternating rows of data.I figured the way to do it was to 1) get the actual row number from the dataset, 2) determine ODD or EVEN using this code from the PHP manual site;
<pre id=code><font face=courier size=2 id=code> if (intval($number / 2) == ($number / 2)) {
$row_bg = "FFFFCC";
} else {
$row_bg = "EEEEEE";
} </font id=code></pre id=code>
And then simply insert an <? echo $row_bg ?> in the color tags in the rows I want to change.
The PROBLEM... I cannot figure out how to get the row number from the DWMX recordset. It has to be there somewhere.
Can someone guide me in determining the present row number for a record?
Thanks
DWMX2004 | PHP 4.3.10 | MySQL 4.0.22
Replies
Replied 09 Feb 2005 15:59:23
09 Feb 2005 15:59:23 Vince Baker replied:
I usually use a simple counter, define a variable = 1 before the repeat region and then have variable = variable + 1 before the close of the repeat region....easy way to get even / odd numbers.
Regards
Vince Baker
<strong>DMX Zone Manager</strong>
[VBScript | ASP | HTML | CSS | SQL | Oracle | AS400 | ERP Logic | Hosting]
Regards
Vince Baker
<strong>DMX Zone Manager</strong>
[VBScript | ASP | HTML | CSS | SQL | Oracle | AS400 | ERP Logic | Hosting]
Replied 09 Feb 2005 18:21:43
09 Feb 2005 18:21:43 K Orian replied:
Vince,
Thanks for the reply. I actually found this answer and coded it this evening after posting. Once again, I was trying to make things harder than they have to be.
For posterity:setting alternating row colors for record set displays.
<font color=blue> <?php
if ($totalRows_rs_results > 0) // Show if recordset not empty
{
$display_row = 1;
php do {
if (intval($display_row / 2) == ($display_row / 2)) { //if record number is even
$row_bg = "FFFFCC" ; } //set BG color to FFFFCC or any color you like
else {
$row_bg = "EEEEEE" ; //else use EEEEEE or any color you like
}
$display_row = $display_row + 1 ; //increment row count for the next cycle
</font id=blue>
Insert your repeat region table here and insert the code to echo $row_bg like this;
<font color=blue>bgcolor="*php echo ($row_bg);*"</font id=blue> The "*" (are supposed to be php tags)
Then close it off at the end like this;
<pre id=code><font face=courier size=2 id=code>
<?php }
} while ($row_rs_results = mysql_fetch_assoc($rs_search_results));
} // Show if recordset not empty ?>
</font id=code></pre id=code>
Then you get contrasted data rows in you output. If anyone has a cleaner way, please share.
Thanks
DWMX2004 | PHP 4.3.10 | MySQL 4.0.22
Edited by - steedvlx on 09 Feb 2005 18:22:45
Thanks for the reply. I actually found this answer and coded it this evening after posting. Once again, I was trying to make things harder than they have to be.
For posterity:setting alternating row colors for record set displays.
<font color=blue> <?php
if ($totalRows_rs_results > 0) // Show if recordset not empty
{
$display_row = 1;
php do {
if (intval($display_row / 2) == ($display_row / 2)) { //if record number is even
$row_bg = "FFFFCC" ; } //set BG color to FFFFCC or any color you like
else {
$row_bg = "EEEEEE" ; //else use EEEEEE or any color you like
}
$display_row = $display_row + 1 ; //increment row count for the next cycle
</font id=blue>
Insert your repeat region table here and insert the code to echo $row_bg like this;
<font color=blue>bgcolor="*php echo ($row_bg);*"</font id=blue> The "*" (are supposed to be php tags)
Then close it off at the end like this;
<pre id=code><font face=courier size=2 id=code>
<?php }
} while ($row_rs_results = mysql_fetch_assoc($rs_search_results));
} // Show if recordset not empty ?>
</font id=code></pre id=code>
Then you get contrasted data rows in you output. If anyone has a cleaner way, please share.
Thanks
DWMX2004 | PHP 4.3.10 | MySQL 4.0.22
Edited by - steedvlx on 09 Feb 2005 18:22:45