You are here: Re: [PHP] How to format every secound row in a database result « PHP « IT news, forums, messages
Re: [PHP] How to format every secound row in a database result

Posted by Jochem Maas on 03/30/05 19:17

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
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация