#1
  1. Full Access
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jun 2000
    Location
    London, UK
    Posts
    2,019
    Rep Power
    17
    How can I get it so that when I run a search, and the results come back in table format, the rows are alternating colours, like on Devshed's forums? I believe there was some code here some time ago saying how to do it...

    --------------------------------------------
    Alex
    (http://www.alex-greg.co.uk)
  2. #2
  3. No Profile Picture
    RyanP
    Guest
    Devshed Newbie (0 - 499 posts)
    yep, there was, search

    it will be something like
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    if $bgcolor == "color1"
    $bgcolor = "color2"
    else
    $bgcolor = "color1"
    print <td bgcolor="$bgcolor">whatever</td>
    [/code]
  4. #3
  5. Full Access
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jun 2000
    Location
    London, UK
    Posts
    2,019
    Rep Power
    17
    Yeah, I found it. It doesn't work for me though. It seems that when I try and define a if ... else loop within a while loop I get parse errors, which is extremely infuriating. Here is my code:

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>

    MYSQL_CONNECT(localhost, user, pass);
    @MYSQL_SELECT_DB(db);

    $result = MYSQL_QUERY("SELECT * FROM noticeboard WHERE (reply = 'yes') AND (thread = '$thread') ORDER BY id asc");

    $i=1;

    while ($row = mysql_fetch_array($result)) {

    $bgcolor = #EBF5FF;

    if (is_int($i/2)) {

    $bgcolor = #99CCFF;

    }

    $body = $row["body"];
    $author = $row["author"];
    $id = $row["id"];

    echo " <tr bgcolor="$bgcolor">n";
    echo " <!-- Reply ID: $id-->n";
    echo " <td bgcolor="$bgcolor" valign="top"><font size="2" face="Arial, Helvetica, sans-serif">n";
    echo " <nobr>$author:</nobr></font></td>n";
    echo " <td colspan="4" bgcolor="$bgcolor"><font size="2" face="Arial, Helvetica, sans-serif">n";
    echo " $bodyn";
    echo " </font></td>n";
    echo " </tr>nn";


    $i++;

    }

    MYSQL_CLOSE();

    [/code]

    I get a parse error on the

    if (is_int($i/2)) {

    line, for some reason. All it does is check for an even number. Please help!!!!

    --------------------------------------------
    Alex
    (http://www.alex-greg.co.uk)
  6. #4
  7. No Profile Picture
    Carpe Diem
    Guest
    Devshed Newbie (0 - 499 posts)
    The errors are related to the code
    $bgcolor = #EBF5FF;

    If you enclose the #EBF5FF in quotes you will fix the errors.

    I.E.
    $bgcolor = "#EBF5FF";

    Regards
    Darren http://www.php4hosting.com/ $ http://www.php4hosting.co.uk/ £
  8. #5
  9. Full Access
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jun 2000
    Location
    London, UK
    Posts
    2,019
    Rep Power
    17
    Thanks bruv. Another lesson learned....

    --------------------------------------------
    Alex
    (http://www.alex-greg.co.uk)
  10. #6
  11. No Profile Picture
    Gödelian monster
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jul 1999
    Location
    Central Florida, USA
    Posts
    2,307
    Rep Power
    62
    This method can be expressed more concisely with the ternary operator.

    example:

    $bgcolor = ($bgcolor=="#FFFFFF") ? "#E3E3E3" : "#FFFFFF";

Similar Threads

  1. Replies: 5
    Last Post: February 13th, 2004, 02:58 PM
  2. Replies: 3
    Last Post: February 11th, 2004, 01:33 PM
  3. League table problem
    By silverduck in forum MySQL Help
    Replies: 8
    Last Post: February 10th, 2004, 12:38 PM

IMN logo majestic logo threadwatch logo seochat tools logo