SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2002
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    printing records with alternating colours

    I would like to print out candidate records in two colour where the bgcolour of a row changes when the ID of a candidate changes. The following is what I have written so far ...

    PHP Code:
     $studPrevious '';
     
    $studCurrent '';
                         
                     
    //Display the results
                     
    while($row mysql_fetch_array($filterQueryResultMYSQL_ASSOC))
                     {
                         
    $studCurrent $row['studentID'];
                         if(
    $studCurrent == $studPrevious)
                         {
                             echo 
    '<tr bgcolor="#CCCCCC" align="center" valign="middle">
                                        <th scope="col">'
    .$row['studentID'].'</th>
                                        <td>'
    .$row['firstName'].'</td>
                                        <td>'
    .$row['secondName'].'</td>
                                     <td>'
    .$row['examDate'].'</td>
                                     <td>'
    .$row['moduleNumber'].'</td>
                                     <td>Yes</td>
                                  </tr>'
    ;
                         }
                         else
                         {
                                   echo 
    '<tr bgcolor="#FFCCCC" align="center" valign="middle">
                                        <th scope="col">'
    .$row['studentID'].'</th>
                                        <td>'
    .$row['firstName'].'</td>
                                        <td>'
    .$row['secondName'].'</td>
                                     <td>'
    .$row['examDate'].'</td>
                                     <td>'
    .$row['moduleNumber'].'</td>
                                     <td>Yes</td>
                                  </tr>'
    ;
                         }            
                         
    $studPrevious $row['studentID'];
                     }
    //whie loop 

  2. #2
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Im not sure if this is what you are after or not but try this article!

    http://www.zend.com/codex.php?id=399&single=1

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Mexico
    Posts
    58
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well you will use a class as far as I now which will be coded from the loop you generate on your table so that every other row would be = to class A which has the atribute of bakground-color: #<color>
    Alexandro Colorado

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,501
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Try to duplicate as little code as possible. That way, if you want to change the layout of the table, or it's content, you only have to change it once.

    PHP Code:
         $studPrevious '';
         
    $studCurrent '';
                        
    //Display the results
         
    while($row mysql_fetch_array($filterQueryResultMYSQL_ASSOC))
         {
             
    $studCurrent $row['studentID'];
             if(
    $studCurrent == $studPrevious)
             {
                  
    $bgcolor "#CCCCCC";
             }
             else
             {
                  
    $bgcolor "#FFCCCC";
             }
             echo 
    '<tr bgcolor="'.$bgcolor.'" align="center" valign="middle">
                          <th scope="col">'
    .$row['studentID'].'</th>
                          <td>'
    .$row['firstName'].'</td>
                          <td>'
    .$row['secondName'].'</td>
                          <td>'
    .$row['examDate'].'</td>
                          <td>'
    .$row['moduleNumber'].'</td>
                          <td>Yes</td>
                      </tr>'
    ;
             
    $studPrevious $row['studentID'];
         }
    //while loop 


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
  •