SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2004
    Location
    USA, Pa. Philly
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question can it be done in PHP


    allternating color rows in a table, I know it can be done with javascript, but was wondering if all so be done in PHP, thx in advance

  2. #2
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    my mobile portal
    ghiris.ro

  3. #3
    SitePoint Wizard wheeler's Avatar
    Join Date
    Mar 2006
    Location
    Gold Coast, Australia
    Posts
    1,369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    function bgcolor()
    {
        global 
    $bgcolor;
        
        if (
    $bgcolor == 'white') {
            
    $bgcolor 'gray';
        } else {
            
    $bgcolor 'white';
        }
        
        echo 
    'class="'.$bgcolor.'"';
        
    }

    while (
    $row mysql_fetch_array($query))
    {
    echo 
    "<tr " bgcolor() . ">";
    echo 
    "<td>&nbsp;</td>";
    echo 
    "</tr>";

    god damn asp is ugly!
    Studiotime - Time Management for Web Developers
    to-do's, messages, invoicing, reporting - 30 day free trial!
    Thomas Multimedia Web Development

  4. #4
    SitePoint Addict CommanderZ's Avatar
    Join Date
    Apr 2006
    Location
    Czech Republic
    Posts
    236
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    $even=true;
    while ($row = mysql_fetch_array($query))
    {
    echo "<tr bgcolor=".$even?"white":"gray".">";
    echo "<td>&nbsp;</td>";
    echo "</tr>";
    $even!=$even;
    }

  5. #5
    SitePoint Evangelist
    Join Date
    Feb 2005
    Posts
    581
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $i 0;
    while (
    $row mysql_fetch_array($query))
    {
      if (
    $i &#37; 2)
        
    $bgcolor "white";
      else
        
    $bgcolor "gray";

    echo 
    '<tr bgcolor="'.$bgcolor.'">';
    echo 
    "<td>&nbsp;</td>";
    echo 
    "</tr>";

      
    $i++;

    Should be percent not 37.
    I will not flame the newbies,
    I will not flame the newbies,
    I will flame the newbies...
    Table free is the way to be!

  6. #6
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just make a loop. Let say you're getting your stuff from database.

    using while loop
    PHP Code:
    echo "<table>";
    $i=0
    // this is a while loop
    while () {
        
    // if the remainder of $i divided by 2 is equals to zero
        
    if ($i&#37;2==0) {
            
    echo "<tr><td></td></tr>";
        } else {
            echo 
    "<tr style='background:#000;'><td></td></tr>";
        }
        
    // increases $i indicator
        
    $i++;
    }
    echo 
    "</table>"
    My Network
    Deluxe Web Directory
    FontCubes Free Fonts

  7. #7
    SitePoint Evangelist
    Join Date
    Feb 2005
    Posts
    581
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $i 0;
    while (
    $row mysql_fetch_array($query))
    {
      if (
    $i 2// i percent two
        
    $bgcolor "white";
      else
        
    $bgcolor "gray";

    echo 
    '<tr bgcolor="'.$bgcolor.'">';
    echo 
    "<td>&nbsp;</td>";
    echo 
    "</tr>";

      
    $i++;

    I will not flame the newbies,
    I will not flame the newbies,
    I will flame the newbies...
    Table free is the way to be!


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
  •