Alternate outputs- NOT random, but in order.

Discussion in 'PHP' started by bigpapa, Sep 3, 2007.

  1. #1
    Hi,

    I was wondering if someone could help me answer this "easy" question:

    I have three variables, lets say $item1, $item2 and $item3

    How would I display these in order, one at a time? For example, I have only one variable right now:

          if (!$show) {
            return $item1;
          }
    Code (markup):
    If I add $item2 and $item3 to the database, how can I get it to display these in numerical order? item1, item2, item3, item1, item2, item3....

    I do not want to use rand() because they need to stay in order.

    Sorry if this sounds confusing... I would really appreciate any help you can give.

    Thanks!
     
    bigpapa, Sep 3, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    Your question is not really clear. Try to rephrase it and post your whole code so we can understand better.
     
    nico_swd, Sep 4, 2007 IP
  3. webrickco

    webrickco Active Member

    Messages:
    268
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Yes, what triggers the display of the variables? The refresh of the page? the user action by pressing a link or a button?

    How the variables are stored? each variable is a row of the table? do we have an ordered structure by row like:

    - row1 : item1 value,
    - row2 : item2 value,
    etc...

    in that case you would be able to use the "limit" keyword of sql to retrieve the next element based on an hidden variable kept into to your form of the last shown element.
     
    webrickco, Sep 4, 2007 IP
  4. bigpapa

    bigpapa Banned

    Messages:
    273
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Sorry for not being clear enough. Here is the full code:

    <?php
    
    
    $body = 'This is some text';
    
    function myfeed($content) {
        global $body;
    
    
        if(is_feed()) {
            return $content.$body;
        } else {
            return $content;
        }
    }
    add_filter('the_content', 'myfeed');
    ?>
    
    PHP:
    Its for wordpress. What you type in $body shows up at the end of your RSS feed, such as a copyright notice or an ad.

    I want to have something like $body2 and $body3 and rotate them in order. For example, each time I make a post, it will add $body, $body2, $body3, $body, $body2.... etc. etc at the end of my posts, rotating them in order.

    I know that there are similar plugins that already exist, but I wanted to work with this code a little bit.

    Again, any help is appreciated. Thanks so much.
     
    bigpapa, Sep 4, 2007 IP