SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need meaning of an if statement.

    This are set ups values on the top of the page
    PHP Code:
    $submenu false;
    $cat = isset($_GET['subject']) && is_numeric($_GET['subject'])?$_GET['subject']:null

    And this line is within the code and uses those values.

    PHP Code:
     if($submenu == false && !is_null($cat) && $cat == $row['id']) 
    What this line means according to the set up values above?

    in Special the $submenu variable why does its value needed to be assign to false here and then use it in that conditioned line?

  2. #2
    SitePoint Addict joaquin_win's Avatar
    Join Date
    Jul 2005
    Location
    Venezuela
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $submenu is false
    $cat will be $_GET['subject'] only if it is set and it's a number, otherwise will be null

    An the if condition means:

    It's not a submenu and the selected (non null) category equals to the id of some $row

    Make sense?

  3. #3
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by co.ador View Post
    in Special the $submenu variable why does its value needed to be assign to false here and then use it in that conditioned line?
    I don't know. It never changes its value between the first line and the if-statement?

  4. #4
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $submenu false
    This assigns a boolean FALSE value to the $submenu variable.

    PHP Code:
    $cat = isset($_GET['subject']) && is_numeric($_GET['subject'])?$_GET['subject']:null
    This sets $cat to the same value as $_GET['subject'], but ONLY if $_GET['subject'] is set AND numeric. Otherwise it sets $cat to NULL.

    PHP Code:
    if($submenu == false && !is_null($cat) && $cat == $row['id']) 
    This means, if the value of $submenu is false ~AND~ $cat is not null ~AND~ if $cat and $row['id'] have the same values.

    Why $submenu needs to be set to false? I have no idea Who wrote this script?

    Make sense?

    Edit: beaten to it!

  5. #5
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you look at the script below now The Boolean false for submenu would be used for the class=submenu, otherwise I wonder why $submenu=false?


    In turns of users interacting with a page Null is equivalent of when I users click on something or not right? Null = a users haven't click on !is_null= a users has click on am i wrong?


    PHP Code:
    $submenu false;
    $cat = isset($_GET['subject']) && is_numeric($_GET['subject'])?$_GET['subject']:null;
    $prod = isset($_GET['menu']) && is_numeric($_GET['menu'])?$_GET['menu']:null
    $menu_type = isset($_GET['menu_type']) && is_string($_GET['menu_type'])?$_GET['menu_type']:null;


    $sql 'SELECT id,Subject FROM menusubjects;'
    $result mysql_query($sql); 

    if(
    $result && mysql_num_rows($result)!=0) { 
         
        echo 
    '<ul id="nav-categories">'
         
        while(
    $row mysql_fetch_assoc($result)) { 
             
            
    $uri 'example1.php?subject='.urlencode($row['id']); 
            
    $class = !is_null($cat) && $cat==$row['id']?' class="selected"':''
             
            echo 
    "\t",'<li',$class,'><a href="',$uri,'">',$row['Subject'].'</a>'
                 
            if(
    $submenu==false && !is_null($cat) && $cat == $row['id']) { // line 58 
                     
                
    $sql2 'SELECT id,shoename FROM regularmenu WHERE menusubject_id = '.mysql_real_escape_string($cat).';'
                
    $result2 mysql_query($sql2); 
                     
                if(
    $result2 && mysql_num_rows($result2)!=0) { 
                         
                    echo 
    "\n\t\t",'<ul class="submenu">',"\n";     
                     
                    while(
    $row2 mysql_fetch_assoc($result2)) { 
                         
                        
    $uri2 $uri.'&menu='.urlencode($row2['id']); 
                        
    $class2 = !is_null($prod) && $prod==$row2['id']?' class="selected"':''
                         
                        echo 
    "\t\t\t",'<li',$class,'><a href="',$uri2,'">',$row2['shoename'],'</a></li>',"\n"
                     
                    } 
                     
                    echo 
    "\t\t",'</ul> <!-- end of ul.submenu -->',"\n";     
                         
                } 
                     
                
    $submenu true
                 
            } 
                 
            echo 
    '</li>',"\n"
             
        } 
             
        echo 
    '</ul> <!-- end of ul#nav-categories -->',"\n 
    this is the whole script and it's set variables on top.

    It was scripted for Oddz and it works wonders I just trying to figure out the meaning of it so I can work with it.

    it does makes sense thanks.

  6. #6
    Grumpy Minimalist
    Join Date
    Jul 2006
    Location
    Ontario, Canada
    Posts
    424
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As an aside, unless you want to accept values like "+0123.45e6" in your querystring, you should use ctype_digit() instead of is_numeric().

    See the manual for more.

    Off Topic:

    When I first saw the thread title I thought we were going to have a philosophical debate about what the if statement "really means"

  7. #7
    SitePoint Wizard co.ador's Avatar
    Join Date
    Apr 2009
    Posts
    1,054
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got you Tarth...

    Man i am trying to put all this together excuse my language expression i am newbie


Bookmarks

Posting Permissions

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