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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Sep 2007
    Posts
    809
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Echoing results with differing background colors?

    Hi all,

    I'm currently echoing some results in a while statement:

    PHP Code:
    <?php
    $query 
    "SELECT * FROM teachingagencies_directory WHERE agencyname LIKE '%$agencyname%' AND region LIKE '%$region%' AND address LIKE '%$city%' AND address LIKE '%$postcode%' $limit";
            
    $result mysql_query($query) or die(mysql_error());
                while (
    $row mysql_fetch_array ($result)) {
        
    ?>
        <a href="agencydetails.php?Name=<?php echo $row['agencyname'];?>"><?php echo $row['agencyname'];?></a>    
        <?php        
        
    echo '<br/>';
        echo 
    '<br/>';
        echo 
    'Address:'.' '.'<span class="normalfont">'.$row['address'].'</span>';
        echo 
    '<br/>';
        echo 
    'Telephone:'.' '.'<span class="normalfont">'.$row['telephone'].'</span>';
        echo 
    '<br/>';?>
        Website: <span class="normalfont"><a href="<?php echo $row['website']?>"><?php echo $row['website'];?></a></span>
    <?php
        
    echo '<br/>';
        echo 
    '<br/>';
    }
    What I'm trying to achieve is giving every other result a light grey background color... but all I can manage is to give all results a light grey background color.

    Can anyone advise?

    Thanks
    Last edited by greens85; 10-26-2009 at 06:23 PM.

  • #2
    New Coder
    Join Date
    Apr 2008
    Location
    Blagoevgrad, Bulgaria
    Posts
    47
    Thanks
    0
    Thanked 8 Times in 8 Posts
    Something like this?

    PHP Code:
    $query "SELECT * FROM teachingagencies_directory WHERE agencyname LIKE '%$agencyname%' AND region LIKE '%$region%' AND address LIKE '%$city%' AND address LIKE '%$postcode%' $limit";
        
    $result mysql_query($query) or die(mysql_error());
        while (
    $row mysql_fetch_array ($result)) {
            
    $i++;
            if (
    $i 1) {
                echo 
    "
                <div style='background-color: #ffffff;'>
                <a href='agencydetails.php?Name=" 
    $row['agencyname'] . "'>" $row['agencyname'] . "</a>
                <br/>
                <br/>
                Address: <span class='normalfont'>" 
    $row['address'] . "</span>
                <br/>
                Telephone: <span class='normalfont'>" 
    $row['telephone'] . "</span>
                <br/>
                Website: <span class='normalfont'><a href='" 
    $row['website'] . "'>" $row['website'] . "</a></span>
                <br/>
                <br/>
                </div>"
    ;
            }
            else {
                echo 
    "
                <div style='background-color: #e6e6e6;'>
                <a href='agencydetails.php?Name=" 
    $row['agencyname'] . "'>" $row['agencyname'] . "</a>
                <br/>
                <br/>
                Address: <span class='normalfont'>" 
    $row['address'] . "</span>
                <br/>
                Telephone: <span class='normalfont'>" 
    $row['telephone'] . "</span>
                <br/>
                Website: <span class='normalfont'><a href='" 
    $row['website'] . "'>" $row['website'] . "</a></span>
                <br/>
                <br/>
                </div>"
    ;
            }
        } 

  • #3
    Regular Coder
    Join Date
    Sep 2007
    Posts
    809
    Thanks
    5
    Thanked 2 Times in 2 Posts
    er40... thats perfect.... just need to move it into css so I can make the page valid!

    Thanks

  • #4
    New Coder
    Join Date
    Apr 2008
    Location
    Blagoevgrad, Bulgaria
    Posts
    47
    Thanks
    0
    Thanked 8 Times in 8 Posts
    In your css:
    PHP Code:
    .color1 background-color#ffffff; }
    .color2 background-color#e6e6e6; } 
    and the div's:

    PHP Code:
    <div class='color1'>
    ...
    <
    div class='color2'


  •  

    Posting Permissions

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