Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2010
    Location
    Kenya
    Posts
    42
    Thanks
    4
    Thanked 1 Time in 1 Post

    PHP display dynamic data on table with alternating row colours

    Hi, I've been trying to display data called from a mysql database to a table with alternating row colors but without luck. A sample code of the same is shown below

    PHP Code:
    <table width="100%" border="0">
      <tr>
        <td><div align="center"></div></td>
        <td><div align="center"></div></td>
        <td><div align="center">Release Date</div></td>
        <td><div align="center">Change Status</div></td>
      </tr>
    <?php
    $now 
    mysql_query("SELECT * FROM table WHERE showing = '1' ORDER BY release_date DESC");
    $nowCount mysql_query("SELECT COUNT(*) AS now FROM table WHERE showing = '1'");
    $numArr mysql_fetch_array($nowCount);
    $num $numArr["now"];
    echo 
    $num." movies are currently listed as now showing.<br><br>";

    while (
    $show mysql_fetch_array($now)) {
        
    $mov_id $show["id"];
        
    $mov_name ucwords($show["name"]);
        
    $thumb SHOW_THUMBNAIL.''.$show["mini"];
        
    $lnk "<a href=\"?s=m&a=v&m=".$mov_id."\">".$mov_name."</a><br>";
        
    $date $show["date"];
        if (
    $date != "-") {
            
    $date strftime("%b %d, 20%y"strtotime($date));
        }
    ?>
      <tr>
        <td width="75px"><div align="center"><a href="?s=m&a=v&m=<?php echo $mov_id?>"><img src="<?php echo $thumb?>" title="<?php echo $mov_name?>" /></a></div></td>
        <td><div align="center"><a href="?s=m&a=v&m=<?php echo $mov_id?>"><?php echo $mov_name?></a></div></td>
        <td><div align="center"><?php echo $date?></div></td>
        <td><div align="center">
          <form id="change" name="change" method="post" action="">
            <a href="?s=s&r=<?php echo $mov_id?>">Out of Theatres
            </a>
          </form>
          </div></td>
      </tr>
      <?php }?>
    </table>
    Any help will be appreciated.

    Biko

  • #2
    Regular Coder poyzn's Avatar
    Join Date
    Nov 2010
    Posts
    266
    Thanks
    2
    Thanked 61 Times in 61 Posts
    sorry, but where in this code snippet you are trying to change row color? Your <tr> has no styles or code

  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,801
    Thanks
    160
    Thanked 2,216 Times in 2,203 Posts
    Blog Entries
    1
    PHP Code:
    <?php
    ..........
    $i=0;
    while (
    $show mysql_fetch_array($now)) { 
    ...........
    ?>
    <tr class="<?php echo ($i%2==0'even':'odd'); $i++;?>">
    Code:
    tr.even td{
    background:#ddd;
    }
    
    tr.odd td{
    background:#fff;
    }
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    bngari (12-24-2010)


  •  

    Posting Permissions

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