co.ador Posted May 20, 2009 Share Posted May 20, 2009 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 https://forums.phpfreaks.com/topic/158906-need-meaning-of-an-if-statement/ Share on other sites More sharing options...
GingerRobot Posted May 20, 2009 Share Posted May 20, 2009 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 https://forums.phpfreaks.com/topic/158906-need-meaning-of-an-if-statement/#findComment-838072 Share on other sites More sharing options...
co.ador Posted May 20, 2009 Author Share Posted May 20, 2009 Thank you ! Link to comment https://forums.phpfreaks.com/topic/158906-need-meaning-of-an-if-statement/#findComment-838090 Share on other sites More sharing options...
co.ador Posted May 20, 2009 Author Share Posted May 20, 2009 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 https://forums.phpfreaks.com/topic/158906-need-meaning-of-an-if-statement/#findComment-838101 Share on other sites More sharing options...
kickstart Posted May 20, 2009 Share Posted May 20, 2009 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 https://forums.phpfreaks.com/topic/158906-need-meaning-of-an-if-statement/#findComment-838113 Share on other sites More sharing options...
co.ador Posted May 20, 2009 Author Share Posted May 20, 2009 $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 https://forums.phpfreaks.com/topic/158906-need-meaning-of-an-if-statement/#findComment-838130 Share on other sites More sharing options...
kickstart Posted May 20, 2009 Share Posted May 20, 2009 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 https://forums.phpfreaks.com/topic/158906-need-meaning-of-an-if-statement/#findComment-838140 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.