Re: How to format every secound row in a database result

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Georg wrote:
Hi!

I wish to format the output of a database select.
The result is presented in a table, in which i'd like to present everey
secound row with a different background color.
My idea was to test if the remaining number of rows where a prime number or

modulo 2 .... is the current row 'number' divisible by 2 with no remainder? (i.e. is it an odd row or an even row)

hint code:

$i = 1;
// assume $rows is your DB resultset
foreach($rows as $row) {
	$bgcolor = ($i % 2) ? '#fff': '#f00';
	$i++;
	$yourColumns = '';
	foreach ($row as $field) {
		$yourColumns =. "<td>$field</td>";
	}
	echo '<tr style="'.$bgcolor.'">',$yourColumns,'<tr>';
}

I really think that prime numbers are not what your looking for....
but maybe you have very specific formatting requirements?!!??

not, and by that determent if the background color should be white or som
ivory-like color to improve the readability in the result table...

Hope to hear from anyone with experience in similar matters...

btw there are quite a few javascript libs that do auto coloring of HTML tables in the way you describe - they are pretty much drag'n'drop scripts - I'll leave finding them up to you ;-)


TIA! Georg Herland, Norway


-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux