Jump to content

Need meaning of an if statement.


co.ador

Recommended Posts

This are set ups values on the top of the page

$submenu = false;
$cat = isset($_GET['subject']) && is_numeric($_GET['subject'])?$_GET['subject']:null;

 

 

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

 

 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?

Link to comment
Share on other sites

why does its value needed to be assign to false here and then use it in that conditioned line?

 

I've absolutely no idea. I assume you didn't write this code, so maybe try asking the person who did?

 

I've no idea what this code does so i can't possibly tell you how it works.

Link to comment
Share on other sites

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?

 

 

$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.

Link to comment
Share on other sites

Hi

 

The code appears to be taking the returned values of the input fields, checking that they exist and are numeric and if so setting a variable to their value. If they are not set or are not numberic it is setting the variable to NULL.

 

I presume subject and menu are drop down lists.

 

$submenu is being used as a marker to process the inner SELECT only on the first time round the outer SELECT.

 

All the best

 

Keith

Link to comment
Share on other sites

 

$submenu is being used as a marker to process the inner SELECT only on the first time round the outer SELECT.

 

 

 

That was the only part I didn't get from your explanation.

 

If you see the $submenu variable is set to the boolean false and then later in the code is set to true why?

 

 

Link to comment
Share on other sites

Hi

 

It is set to false so that the if statement if($submenu==false && !is_null($cat) && $cat == $row['id']) { // line 58 is true. However within that if if statement it sets it to true so that on any subsequent times it gets to that if statement is will be false and the inner code will no be executed.

 

All the best

 

Keith

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.