Thanks very much John.

I found the following and inserted it into my snippet for alternating
backgoriund colors.

However, I'm not sure I understand the logic.

This part:
...............................

$alternate = "2";
   while ($posts_info = mysql_fetch_array($get_posts_res)) {
       $post_id = $posts_info['post_id'];
       $post_text = nl2br(stripslashes($posts_info['post_text']));
       $post_create_time = $posts_info['fmt_post_create_time'];
       $post_owner = stripslashes($posts_info['post_owner']);

if ($alternate == "1") {
$color = "#eaf3da";
$alternate = "2";
}
else {
$color = "#d5eae9";
$alternate = "1";
}
........................

Best...
Tony
.........................

$display_block = "
   <P>Showing posts for the <strong>$topic_title</strong> topic:</p>

   <table width=100% cellpadding=3 cellspacing=1 border=0>
   <tr>
   <th bgcolor=\"#497fbf\"><font color=\"#ffffff\">AUTHOR</font>
   </th>
   <th bgcolor=\"#497fbf\"><font color=\"#ffffff\">POST</font></th>
   </tr>";
   $alternate = "2";
   while ($posts_info = mysql_fetch_array($get_posts_res)) {
       $post_id = $posts_info['post_id'];
       $post_text = nl2br(stripslashes($posts_info['post_text']));
       $post_create_time = $posts_info['fmt_post_create_time'];
       $post_owner = stripslashes($posts_info['post_owner']);

if ($alternate == "1") {
$color = "#eaf3da";
$alternate = "2";
}
else {
$color = "#d5eae9";
$alternate = "1";
}


       //add to display
       $display_block .= "
       <tr>
       <td width=35% valign=top bgcolor=\"$color\"><p><a
href=mailto:$post_owner>$post_owner<br></a>[$post_create_time]</td>
       <td width=65% valign=top bgcolor=\"$color\"><p>$post_text<br><br>
       <a href=\"replytopost.php?post_id=$post_id\"><img src=\"reply.gif\"
border=\"0\" align=\"right\"></a></td>

       </tr>";

   }

  //close up the table
  $display_block .= "</table>";


----- Original Message -----
From: "John W. Holmes" <[EMAIL PROTECTED]>
To: "Anthony Ritter" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Tuesday, August 19, 2003 9:59 PM
Subject: Re: [PHP] mysql output


> Anthony Ritter wrote:
>
> >>You also asked a very, very common question, i.e. how to alternate
colors
> >
> > in
> >
> >>table rows... there are a ton of websites/tutorials out there that
explain
> >>ways to do this.
> >>
> >>---John Holmes...
> >
> > ........................................
> >
> > Apologies for the lengthy code.
> >
> > I've tried using a few tutorials and am still adrift.
> >
> > Here's a snippet:
> >
> > Thank you for any assistance.
> > Tony Ritter
> > ..................
> >
> > <?
> >
> > <table width=100% cellpadding=3 cellspacing=1 border=1>
> >    <tr>
> >    <th bgcolor=\"#497fbf\"><font color=\"#ffffff\">AUTHOR</font>
> >    </th>
> >    <th bgcolor=\"#497fbf\"><font color=\"#ffffff\">POST</font></th>
> >    </tr>";
> >
> >    while ($posts_info = mysql_fetch_array($get_posts_res)) {
> >        $post_id = $posts_info['post_id'];
> >        $post_text = nl2br(stripslashes($posts_info['post_text']));
> >        $post_create_time = $posts_info['fmt_post_create_time'];
> >        $post_owner = stripslashes($posts_info['post_owner']);
> >
> >        $color1 = "#CCFFCC";
> >        $color2 = "#BFD8BC";
> >        $posts_info = 0;
>
> Move the above line outside of your while loop
>
> >        $row_color = ($posts_info % 2) ? $color1 : $color2;
>
> $row_color = ($posts_info++ % 2) ? $color1 : $color2;
>
> You were setting $posts_info to zero in each loop, so it's never going
> to change. You must set it to zero outside of the loop, then increment
> it within.
>
> You could make this real easy and just do:
>
> $row_color = ($row_color == $color1) ? $color2 : $color1;
>
> --
> ---John Holmes...
>
> Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
>
> PHP|Architect: A magazine for PHP Professionals – www.phparch.com
>
>
>
>
> ---
> [This E-mail scanned for viruses by gonefishingguideservice.com]
>
>

---
[This E-mail scanned for viruses by gonefishingguideservice.com]


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

Reply via email to