#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    14
    Rep Power
    0

    Help wording an IF statement


    Ok im relatively new to PHP and not sure how to word this IF statement properly.


    if (the $lev1['name'] is the last 'name' in the array) {
    echo "</div>";
    } else {
    echo "<br />";
    }

    Assistance would be appreciated.
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    Show the loop you're using.

    You could also just print the </div> after your loop is finished.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    14
    Rep Power
    0
    What do you mean show the loop im using?

    I would place the </div> after the loop however this loop will be nested inside of another while loop.

    Originally Posted by ManiacDan
    Show the loop you're using.

    You could also just print the </div> after your loop is finished.
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    119
    Rep Power
    33
    They mean the code for the while and / or foreach loops you are using - we need to see them to advise you correctly.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    14
    Rep Power
    0
    PHP Code:
    <?php                   
                        $lev1_set 
    mysql_query("SELECT id, name, title, supername 
                                            FROM level1
                                            ORDER BY name ASC"
    $connection);                    
                        
    $lev2_set mysql_query("SELECT id, name, title, supername 
                                            FROM level2
                                            ORDER BY name ASC"
    $connection);
                        
    $lev3_set mysql_query("SELECT id, name, title, supername 
                                            FROM level3
                                            ORDER BY name ASC"
    $connection);
                        
    $lev4_set mysql_query("SELECT id, name, title, supername 
                                            FROM level4
                                            ORDER BY name ASC"
    $connection);
                    
    ?>

                    <!--content output starts here-->
                    
                    <?php    
                            
    while (($lev1 mysql_fetch_array($lev1_set)) && ($lev1['supername'] == "none")){
                                echo   
    "<div id='outer_bubble'>
                                        <div id='bubble'> " 

                                        
    $lev1['name'] .
                                         
    "<br />
                                        
    {$lev1['title']} <br />
                                        </div><br />"
    ;
                                        
    $parent1 $lev1['name'];
                                        
                                        
                                        
    //THE IF LOOP SHOULD GO HERE
                                        
                                        
                                        
    while (($lev2 mysql_fetch_array($lev2_set)) && ($lev2['supername'] == $parent1)) {
                                            echo   
    "<div id='outer_bubble'>
                                                    <div id='bubble'> " 

                                                    
    $lev2['name'] .
                                                    
    "<br />
                                                    
    {$lev2['title']} <br />
                                                    </div>"
    ;
                                                    
    $parent2 $lev2['name'];

                                                                                                      
    //THE IF LOOP SHOULD GO HERE

                                                    
    while (($lev3 mysql_fetch_array($lev3_set)) && ($lev3['supername'] == $parent2)) {
                                                        echo   
    "<div id='outer_bubble'>
                                                                <div id='bubble'> " 

                                                                
    $lev3['name'] .
                                                                
    "<br />
                                                                
    {$lev3['title']} <br />
                                                                </div>"
    ;
                                                                
    $parent3 $lev3['name'];

                                                                                                                             
    //THE IF LOOP SHOULD GO HERE
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2003
    Posts
    3,505
    Rep Power
    594
    Please edit your post and enclose the code in [ PHP ] tags. See ManiacDan's New User Guide to see how to format a post. It makes it much easier for us to read and advise you.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    14
    Rep Power
    0
    Apologies, I have corrected that.
  14. #8
  15. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    98
    Rep Power
    2
    Nevermind. You will use the Modulus Operator % to determine if the count variable you're going to set above the while statement reaches the number of mysql_num_rows variable?? I think... can somebody else expand a little?
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    14
    Rep Power
    0
    Hmm ok i see what you are saying, im going to play with that and see what i can work up. I appreciate it.

    Any other recommendations are welcome.

    Originally Posted by BitZoid
    Nevermind. You will use the Modulus Operator % to determine if the count variable you're going to set above the while statement reaches the number of mysql_num_rows variable?? I think... can somebody else expand a little?

IMN logo majestic logo threadwatch logo seochat tools logo