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
    Regular Coder
    Join Date
    Oct 2005
    Location
    Newberg, Oregon
    Posts
    252
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Dynamic entry style alternation

    I'm looking for how to implement a basic idea. For example, I have an admin section where I can update a link exchange. So, there are several entries. Is there a way to alternate styles, like to make the first entry have a gray background, the next have light gray, the next gray....and so on. Not so much that exact thing, but that principle. A perfect example is at http://www.generationchurch.org/audio
    Last edited by JustinSainton; 06-24-2006 at 08:29 PM.

  • #2
    Regular Coder
    Join Date
    Aug 2004
    Location
    The US of A
    Posts
    767
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Assuming you have your SQL all worked out...

    PHP Code:
    echo '<ul>';
    $i 0;
    while(
    $row mysql_fetch_array($results)) {
    if(
    $i%== 0)
    {
    $class =' class="style" ';}
    echo 
    '<li'$class '><a href="' $row['link'] . ' title="' $row['title'] . '>' $row['text'] . '</a></li>';
    $i++;

    That should do it. It's been a while since I've used the modulus function though.

  • #3
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    The way I did it is I set up a toggle field, which I then change by dividing the toggle+1 by the max colors and assigning the modulus. Maybe this will help:

    PHP Code:
    <?php
    //set up array with names of the two CSS classes that will display a white or gray background
    $colorArray = {'whiteBG''grayBG'};

    //initialize the toggle field
    $toggleBGColor 0;

    //Indicate how many different colors there can be
    $maxColors 2;

    //loop through data to be displayed
    for ($i 0$i count(dataArray); $i++) {

        
    //print the HTML to actually display using the correct CSS class
        
    print "<div class=\"{$colorArray[$toggleBGColor]}\">{$dataArray['theData']}\n";

        
    //assign the new color array index by using the modulus
        
    $toggleBGColor = ($toggleBGColor 1) % $maxColors;
    }


  •  

    Posting Permissions

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