Re: :: Alternating Rows :: Script With More Explaining ::
| From: | Pierre-Alain Joye | Date: | Fri, 07 Dec 2001 15:16:47 +0000 |
| Subject: | Re: :: Alternating Rows :: Script With More Explaining :: | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-14866@lists.php.net to get a copy of this message | ||
On Thu, 6 Dec 2001 23:07:13 +0200
"Vins" <vins@webonline.co.za> wrote:
> The code is supposed to look like this...
> (Example of code only)
> ____________________________________
>
> <?php
>
> $dbc = mysql_connect("host", "un", "pwd") or die ("Failed
> Connecting to
> Database");
> @mysql_select_db("dbname") or die ("Failed to Select Databse");
>
> $query = "Select name, surname, email from users";
> $result = mysql_query($query) or die ("Failed to Query Database");
>
> if(isset($result)) {
> $i = 1;
>
> while($row = mysql_fetch_array($result)) {
> $name = $row["name"];
> $surname = $row["surname"];
> $email = $row["email"];
>
> if(ereg("1$|3$|5$|7$|9$", $i)) {
> $bg[$i] = "#FFFFFF";
> } else {
> $bg[$i] = "#CCCCCC";
> }
>
> echo "<TR BGCOLOR=\"".$bg[$i]."\">\n";
> echo "<TD>".$name."</TD>\n";
> echo "<TD>".$surname."</TD>\n";
> echo "<TD>".$email."</TD>\n";
> echo "</TR>\n";
>
> $i++;
> }
> }
$aBgColors = array("#999999","#FFFFFF");
while(whateveryouwant){
$i = $iCpt++ % 2;
echo "<TR BGCOLOR=\"".$bg[$i]."\">\n";
}
or more generally with css
$aBgColors = array("evenrow","oddrow");
while(whateveryouwant){
$i = $iCpt++ % 2;
echo "<TR CLASS=\"".$bg[$i]."\">\n";
}
hth
pa
--
Pierre-Alain Joye
Freelance
Developpements et Services web/intranet
pajoye@tuxfamily.org