Professional Web Applications Themes

Using simple PHP code to alternate table row colors but color is all gree. - PHP Development

I am using a super simple PHP alternating row color code but my rows are always coming out green. The code is really simple. the value for i is set to zero then each time a row is written the value $bgcolorvar is reset to either yellow or blue. The back ground color for that line is then set to the variable bgcolorvar. The problem is each line displays green. To verify I coded this right I even put in the command to echo the value of bgcolorvar in the first cell of each line. And sure enough it flips ...

  1. #1

    Default Using simple PHP code to alternate table row colors but color is all gree.

    I am using a super simple PHP alternating row color code but my rows are
    always coming out green. The code is really simple. the value for i is set
    to zero then each time a row is written the value $bgcolorvar is reset to
    either yellow or blue. The back ground color for that line is then set to
    the variable bgcolorvar. The problem is each line displays green. To
    verify I coded this right I even put in the command to echo the value of
    bgcolorvar in the first cell of each line. And sure enough it flips between
    writing blue or yellow in each
    cell. To confirm that I didnt goof up something else I manually set
    bgcolor="blue" on the line where I have it set to bgcolor="$bgcolorvar" and
    sure enough it turned blue.

    The only way I can get it to change colors is to give the variable a new
    name of a differnt length. Sometimes when I do that ALL the rows turn to
    magenta. The real kicker is I tried 3 or 4 differnt scripts for
    alterntating line color and everyone did the same thing.

    I am running this on apache 1.39 (I think, well it is the 1.XX version of
    apache) with the latest non-beta release of php.

    Any idea what I am doing wrong?


    <table border="1" cellspacing="0" cellpadding="0">

    <tr bgcolor="#003366" class="tableheader">
    <td ><div align="center" class="style1">Name</div></td>
    </tr>

    <?php $i = 0; ?>

    <?php do { ?>
    <?php $bgcolorvar = ($i++ & 1) ? 'yellow' : 'blue'; ?>


    <tr bgcolor="$bgcolorvar">

    <td ><div align="center"><?php echo $bgcolorvar ?><?php echo
    $row_rsPayments['item_name']; ?>&nbsp;</div></td>
    <td>

    <?php } while ($row_rsPayments = mysql_fetch_assoc($rsPayments)); ?>
    </table>


    Rich Zellmer Guest

  2. #2

    Default Re: Using simple PHP code to alternate table row colors but color is all gree.

    On Sun, 13 Jun 2004 15:09:59 -0400, "Rich Zellmer"
    <tdmailbox> wrote:
    >Any idea what I am doing wrong?
    >
    > <tr bgcolor="$bgcolorvar">
    try this:

    <tr bgcolor="<? echo $bgcolorvar?> ">

    Regards

    Marian
    --
    Tipps und Tricks zu PHP, Coaching und Projektbetreuung
    [url]http://www.heddesheimer.de/coaching/[/url]
    Marian Heddesheimer Guest

  3. #3

    Default Re: Using simple PHP code to alternate table row colors but color is all gree.

    > >Any idea what I am doing wrong?
    > >
    > > <tr bgcolor="$bgcolorvar">
    >
    > try this:
    >
    > <tr bgcolor="<? echo $bgcolorvar?> ">
    Does that not has to be <tr bgcolor="<? echo ("$bgcolorvar");?> "> ??
    If it is not, why not? That just looks to me the best way to print an
    echo... And a PHP code line you have to end with ; ...

    Ciao4now,

    Jorick
    mail (at) jorickdelange (dot) nl


    - ---[Jorick]--- - Guest

  4. #4

    Default Re: Using simple PHP code to alternate table row colors but color is all gree.

    > Does that not has to be <tr bgcolor="<? echo ("$bgcolorvar");?> "> ??
    > If it is not, why not? That just looks to me the best way to print an
    > echo... And a PHP code line you have to end with ; ...
    I figured it out myself, it is both possible. :-)

    Ciao,

    Jorick
    mail (at) jorickdelange (dot) nl


    - ---[Jorick]--- - Guest

  5. #5

    Default Re: Using simple PHP code to alternate table row colors but color is all gree.


    "- ---[Jorick]--- -" <jorickdelange_removethisplanet.nl> wrote in message
    news:caieq0$ghq$1reader10.wxs.nl...
    > Does that not has to be <tr bgcolor="<? echo ("$bgcolorvar");?> "> ??
    > If it is not, why not? That just looks to me the best way to print an
    > echo... And a PHP code line you have to end with ; ...
    >
    * The ; indicates the end of a statement, as does ?> in a single line
    statement.
    * You can use both echo("") and echo "", because echo isn't a function, but
    a language construct.

    BTW, an alias for the echo call is an equals sign, so you can even do:

    <?= $bgcolorvar ?>


    JW



    Janwillem Borleffs Guest

Similar Threads

  1. Table & Cell Border Colors?
    By Luka Canucka in forum Macromedia Dynamic HTML
    Replies: 3
    Last Post: December 7th, 12:11 PM
  2. Alternate Dynamic Table Row Colour
    By cm2112 in forum Macromedia Dynamic HTML
    Replies: 3
    Last Post: October 31st, 04:35 PM
  3. asp alternate row color
    By Russ in forum Dreamweaver AppDev
    Replies: 2
    Last Post: April 26th, 03:18 AM
  4. Netscape - no table colors showing using CSS
    By Jged webforumsuser@macromedia.com in forum Macromedia Dreamweaver
    Replies: 3
    Last Post: July 20th, 11:32 PM
  5. Replies: 2
    Last Post: June 25th, 01:14 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139