SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Help Please!!!

  1. #1
    SitePoint Enthusiast
    Join Date
    May 2003
    Location
    Lincoln NE
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Help Please!!!

    Genrating Table with 2 diffirent row colors from a WHILE statement

    I'm having problems generating a table with 2 diffirent row colors from my WHILE STATEMENT.

    here is my code:

    while ($row = mysql_fetch_array($query)) {
    $id = $row['ID'];
    $company = $row['COMPANY'];
    $code = $row['CODE'];
    $address = $row['ADDRESS'];
    $date = $row['MDATE'];
    echo("<TR><TD ALIGN='left'>$company</TD>".
    "<TD ALIGN='center'>$code</TD>".
    "<TD ALIGN='left'>$address</TD>".
    "<TD ALIGN='center'>$date</TD>".
    "<TD ALIGN='center'><a href='delete.php?id=$id'>EDIT</A></TD>".
    "<TD ALIGN='center'><a href='delete.php?id=$id'>DELETE</A></TD></TR>");
    if ($row) continue;
    echo("<TR BGCOLOR='#C0C0C0'><TD ALIGN='left'>$company</TD>".
    "<TD ALIGN='center'>$code</TD>".
    "<TD ALIGN='left'>$address</TD>".
    "<TD ALIGN='center'>$date</TD>".
    "<TD ALIGN='center'><a href='delete.php?id=$id'>EDIT</A></TD>".
    "<TD ALIGN='center'><a href='delete.php?id=$id'>DELETE</A></TD></TR>");

    Any help is greatly appericated. Thanks much

  2. #2
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi.

    the code below will store the current row color in a variable called $rowcolour which you can then use in your echo statement:

    PHP Code:
    $i 0;
    while (
    $row mysql_fetch_array($query)) {

       
    // you can change the colours here
       
    $rowcolour = ($i++ % == 0)  ? '#FFFFFF' '#C0C0C0';

       
    $id $row['ID'];
       
    $company $row['COMPANY'];
       
    $code $row['CODE'];
       
    $address $row['ADDRESS'];
       
    $date $row['MDATE'];

       echo 
    "<TR bgcolor='$rowcolour'><TD ALIGN='left'>$company</TD>
       <TD ALIGN='center'>
    $code</TD>
       <TD ALIGN='left'>
    $address</TD>
       <TD ALIGN='center'>
    $date</TD>
       <TD ALIGN='center'><a href='delete.php?id=
    $id'>EDIT</A></TD>
       <TD ALIGN='center'><a href='delete.php?id=
    $id'>DELETE</A></TD></TR>";

    Last edited by Chris82; May 17, 2003 at 19:25.


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
  •