adrumsolo4u Posted February 22, 2007 Share Posted February 22, 2007 i have been searching for a tutorial to explain to me how to do a simple task, but cannot find one. here is what I'd like to do: have a link such as this one <a href="?menu=1&sub='variable'">click me</a> to allow a user to click, and for the link to output a constant (in this case, 1) and also gather a variable. ("variable") then i will need code to find the values of both "menu" and "sub1" and have those values stored temporarily, until they are change by another link, such as <a href="?menu='variable'&sub=1">click me too!</a> i am not sure if i explained enough... any suggestions? Quote Link to comment Share on other sites More sharing options...
ki Posted February 22, 2007 Share Posted February 22, 2007 Use this. <?php if($_GET['page'] == "WOW") { if($_GET['sub'] == "") { echo "FIRST PAGE!?!?!?!?!?"; } if($_GET['sub'] == "2") { echo "SECOND OMG LEET"; } } ?> Quote Link to comment Share on other sites More sharing options...
adrumsolo4u Posted February 22, 2007 Author Share Posted February 22, 2007 could i do this? <?php private m_page; private m_sub; if($_GET['page'] == "0") { return 0; } else { $_GET['page'] ==m_page; } if($_GET['sub'] == "0") { return 0; } else { $_GET['sub'] ==m_sub; } ?> that would be cool if i could. Quote Link to comment Share on other sites More sharing options...
adrumsolo4u Posted February 22, 2007 Author Share Posted February 22, 2007 oops i mean this: <?php private $m_page; private $m_sub; if($_GET['page'] == "0") { return 0; } else { $this->m_page = $_GET['page']; } if($_GET['sub'] == "0") { return 0; } else { $this->m_sub = $_GET['sub']; } ?> Quote Link to comment Share on other sites More sharing options...
ki Posted February 22, 2007 Share Posted February 22, 2007 im not sure what your trying to achieve. Quote Link to comment Share on other sites More sharing options...
adrumsolo4u Posted February 22, 2007 Author Share Posted February 22, 2007 i just want a way to GET the values, because i have a different function which will use the new private variables <?php if ($m_sub=="3") echo "<li><a href='#'><span2>+ Page 3.1</span2></a></li><li><a href='#'><span2>+ Page 3.2</span2></a></li>"; ?> Quote Link to comment Share on other sites More sharing options...
Yesideez Posted February 22, 2007 Share Posted February 22, 2007 This may help as well... <?php $code=myfunc($_GET['menu'],$_GET['variable']); ... function myfunc($menu,$var) { { if (empty($menu)||empty($var)) { $retvar=0; } else { if ($_GET['menu']=="1") { if ($_GET['variable']=="0") { echo "Menu 1, variable 0"; $retvar=1; } else if ($_GET['variable']=="1") { echo "Menu 1, variable 1"; $retvar=2; } else { echo "Menu 1, variable not known"; $retvar=3; } } else { echo "Menu unknown"; $retvar=4; } } return $retvar; } ?> EDIT: Accidentally used different names for the function. Quote Link to comment Share on other sites More sharing options...
Yesideez Posted February 22, 2007 Share Posted February 22, 2007 Basically the cariable $code would contain 0-4 but by adding more ifs you can allow for more functionality although what I've supplied is just an example. If you want help on catering for more data I'd advise on using switch instead. Quote Link to comment Share on other sites More sharing options...
adrumsolo4u Posted February 22, 2007 Author Share Posted February 22, 2007 what i'm trying to do is create a nav menu if lets say "1" were clicked, the variable would become 1, and an if statement containing the two subs would allow it to print the html, while the subs from the other main categories (2,3,4) are not printed, because their if statement is not true. 1 +1.1 +1.2 2 3 4 Quote Link to comment Share on other sites More sharing options...
adrumsolo4u Posted February 22, 2007 Author Share Posted February 22, 2007 example: pagevar =(whatever value); echo 1 if pagevar=1{ echo +1.1 echo +1.2 } echo 2 if pagevar=2{ echo +2.1 echo +2.2 } Quote Link to comment Share on other sites More sharing options...
Yesideez Posted February 22, 2007 Share Posted February 22, 2007 Had a feeling you were. Sorry for the delay in replying but I just had major problems getting this to display properly. Off the top of my head, can't guarantee it'll work first time. <?php $menu=$_GET['menu']; $sub=$_GET['sub']; //Just so you can see what was pulled from the URL echo 'You selected '.$menu.((!empty($sub)) ? " and sub menu ".$sub : "").'<br /><br />'; //Now we build the menu echo '<a href="menu.php?menu=1">Option 1</a><br />'; if ($menu==1) { echo '<a href="menu.php?menu=1&sub=1">Menu 1 Sub 1</a><br />'; echo '<a href="menu.php?menu=1&sub=2">Menu 1 Sub 2</a><br />'; } echo '<a href="menu.php?menu=2">Option 2</a><br />'; if ($menu==2) { echo '<a href="menu.php?menu=2&sub=1">Menu 2 Sub 1</a><br />'; echo '<a href="menu.php?menu=2&sub=2">Menu 2 Sub 2</a><br />'; } echo '<a href="menu.php?menu=3">Option 3</a><br />'; if ($menu==3) { echo '<a href="menu.php?menu=3&sub=1">Menu 3 Sub 1</a><br />'; echo '<a href="menu.php?menu=3&sub=2">Menu 3 Sub 2</a><br />'; } ?> Quote Link to comment Share on other sites More sharing options...
adrumsolo4u Posted February 22, 2007 Author Share Posted February 22, 2007 actually, after taking out the "menu.php5" before the rest of the code in the links, it worked perfectly. thank you very much for your assistance in ending my aggravating dilemma. Quote Link to comment Share on other sites More sharing options...
Yesideez Posted February 22, 2007 Share Posted February 22, 2007 Glad to have been able to help Quote Link to comment Share on other sites More sharing options...
Yesideez Posted February 22, 2007 Share Posted February 22, 2007 It's quite easy to add a hidden menu system although this wouldn't be secure and isn't really recommended for anything serious. Add this after the last if... if ($menu==2118) { echo '<a href="menu.php?menu=2118&sub=1">Menu secret Sub 1</a><br />'; echo '<a href="menu.php?menu=2118&sub=2">Menu secret Sub 2</a><br />'; } That way you'd have to edit the URL in the address bar to change menu to the value of 2118 but only the sub menu would show and you'd never get a menu option for that secret menu showing. All in the name of fun Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.