SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    334
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    CSS Styling A PHP Generated Table

    I have a layout on my table cells which I guess some people call a zebra layout. All the odd rows are say blue and all the even are blue. So say the first row blue, second red and so on... It's easy to do this in a simple table, but for my php page which shows the results do they all have to be odd? Of anyone can tell me a simple way of doing this...

    Code:
      <tr valign="top" class="odd">
        <td><?php echo $qry['FirstName']; ?></td>
    	<td><?php echo $qry['LastName']; ?></td>
        <td><?php echo date('d/m/Y', strtotime($qry['DateOfBirth'])); ?></td>
        <td><?php echo($qry['loginDateTime']?date('d/m/Y H:i:s', strtotime($qry['loginDateTime'])):'N/A'); ?></td>
        <td><?php echo $qry['State'];?></td>
        <td><?php echo $q['Name'];?></td>
      </tr>
    <?php
       }
    }
    
    echo '</table>';
    ?>

  2. #2
    SitePoint Addict tina88's Avatar
    Join Date
    Jan 2007
    Location
    UK
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    334
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok I tried this but no luck... Can anyone take a look?

    PHP Code:
    <?php

    /* connect to the mysql database and use a query to get the members info */

    include 'configure.php';
    include 
    'open.php';
    //navigation

    include("nav.php");

    //assign the bday variable.
    $month $_REQUEST['month'];

    $color1 "#CCFFCC";  
    $color2 "#BFD8BC";  
    $row_count 0;

    //birthday search
    $info mysql_query("SELECT * FROM `tblmembers` WHERE (MONTH(DateOfBirth) = '{$month}') AND `MemberApproved`='A'");
    ?>

    <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
    Brithday Month: <select name="month">
      <option>Select A Month</option>
      <option value="1">January</option>
      <option value="2">February</option>
      <option value="3">March</option>
      <option value="4">April</option>
      <option value="5">May</option>
      <option value="6">June</option>
      <option value="7">July</option>
      <option value="8">August</option>
      <option value="9">September</option>
      <option value="10">October</option>
      <option value="11">November</option>
      <option value="12">December</option>
    </select>
    <input type="submit" value="Search">
    </form>

    <?php
    echo '<table width="700" border="0" cellspacing="0" cellpadding="0">
      <caption>MEMBERS - BIRTHDAYS SEARCH Download Details</caption>
      <thead>
      <tr>
        <th scope="col" class="left">FIRST NAME</th>
        <th scope="col">LAST NAME</th>
        <th scope="col">DATE OF BIRTH</th>
        <th scope="col">LAST LOGIN</th>
        <th scope="col" class="right">STATE</th>
      </tr>
      </thead>
      <tr class="odd">
        <td>On Hold </td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>'
    ;

    if (
    mysql_num_rows($info) < 1) {
    echo 
    '<tr valign="top">
      <td colspan="5>There are no members that match the query. Please go back and try again</td>
        </tr>'
    ;
    }

    else {
       while (
    $qry mysql_fetch_array($info)) {

    $rep $qry['rep_NBR'];

        
    $repInfo mysql_query("SELECT * FROM `tblrepresentatives` WHERE `rep_NBR`='$rep'");
        
    $q mysql_fetch_array($repInfo);
        
    $row_color = ($row_count &#37; 2) ? $color1 : $color2; 

    //create the layout
    ?>
    <link href="cs_style.css" rel="stylesheet" type="text/css" />

      <tr valign="top">
        <td bgcolor="$row_color" ><?php echo $qry['FirstName']; ?></td>
        <td bgcolor="$row_color"><?php echo $qry['LastName']; ?></td>
        <td bgcolor="$row_color"><?php echo date('d/m/Y'strtotime($qry['DateOfBirth'])); ?></td>
        <td bgcolor="$row_color"><?php echo($qry['loginDateTime']?date('d/m/Y H:i:s'strtotime($qry['loginDateTime'])):'N/A'); ?></td>
        <td bgcolor="$row_color"><?php echo $qry['State'];?></td>
        <td bgcolor="$row_color"><?php echo $q['Name'];?></td>
      </tr>
    <?php
    $row_count
    ++;

       }

    }

    echo 
    '</table>';
    ?>

  4. #4
    SitePoint Addict tina88's Avatar
    Join Date
    Jan 2007
    Location
    UK
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $row_color is a php variable so it needs to be inside php tags.

    try
    PHP Code:
    <td bgcolor="<?php echo $row_color ?>" ><?php echo $qry['FirstName']; ?></td>


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
  •