SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast XploreR's Avatar
    Join Date
    May 2001
    Location
    Singapore
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    code:


    $tables = array("action", "adventure");

    foreach ($tables AS $table) {

    $sql = "SELECT game, url FROM $table
    WHERE gamesystem='playstation'";

    $result = mysql_query($sql);

    while ($row = mysql_fetch_array($result)) {
    // for convenience I use the function extract() to place
    // each element (result set field) contained in $row
    // into its own variable; ie, $game, $url
    extract($row);

    // Now insert into the array $games the key/value pair $game/$url
    $games["$game"] = $url;
    }

    }
    // now sort the array by its keys
    ksort($games);

    echo '<table>';
    while (list ($key, $val) = each ($games)) {
    echo "<tr><td><a href='$val'>$key</a></td></tr>";
    }
    echo '</table>';



    Is it possible to have the output have alternating table colours for the next data

    Example:

    <tr><td bgcolor="#111111><a href='$val'>$key</a></td></tr>
    followed by
    <tr><td bgcolor="#222222"><a href='$val'>$key</a></td></tr>

    and it goes on repeating. Possible?

  2. #2
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sure... just have a toggle variable that you alternate the value of every loop iteration.

    If the toggle is one value, set the table background to one color. If the toggle is the other value, use the other color.

    If you'd like a code example, let me know.
    Travis Burnside
    travis@qwk.net

    Free monitoring for your web site - http://www.qwkmon.com

  3. #3
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I thought I had posted a reply - but nothing here. Oh well, one more time...

    This thread discusses what you want to do
    http://www.sitepointforums.com/showt...threadid=22996

    For example:
    PHP Code:
    while (list ($key$val) = each ($games)) { 
       
    $color = ($i++ % ) ? '#FFFFFF' '#000000';
       echo 
    "<tr><td bgcolor='$color'><a href='$val'>$key</a></td></tr>"



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
  •