Craig Hopson Posted May 4, 2012 Share Posted May 4, 2012 Hi guys, ok this is the situation i have this basic menu example... <a href="upload.php" class="navbarmenu2" >UPLOAD A PHOTO<br><font size="2" color="lightgray">click here to upload<br>your photos now</font></A><a href="view.php" class="navbarmenu2" >VIEW YOUR PHOTOS<br><font size="2" color="lightgray">click here to view<br>your photos now</font></A><a href="viewm.php" class="navbarmenu2">VIEW MESSAGES<br><font size="2" color="lightgray">click here to view<br>your messages</font></A><p><a href="slide.php" class="navbarmenu2">VIEW SLIDESHOW<br><font size="2" color="lightgray">click here to view<br>a slideshow of your photos</font></A><a href="myinfo.php" class="navbarmenu2">INFORMATION<br><font size="2" color="lightgray">click here to view<br>account information</font></A><a href="zip.php?id=<?echo $_COOKIE["id"];?>" class="navbarmenu2">DOWNLOAD<br><font size="2" color="lightgray">click here to download<br>all your photos</font></A><p><a href="settings.php" class="navbarmenu2">SETTINGS<br><font size="2" color="lightgray">click here to view<br>account settings</font></A> as you can see this requires 7 other files to run is there a way to use less files or even just one file without using the $_GET or $_POST varables??maybe functions (PHP) not javascript (i REALLY cant do that YET) lol a example script would be nice if any one has time Thanks Link to comment Share on other sites More sharing options...
thescientist Posted May 4, 2012 Share Posted May 4, 2012 It only really makes sense to combine (say like a Class) if their functionality is related. So for instance, you could group all the "view" related scripts into one. Ultimately, it depends on your application and what makes sense. I mean, you could just throw everything in together, but then you would have one monster script that would be a pain to manage. If you keep your scripts small, logically related, and concise (like Classes offer, and TDD promotes) you may have a couple more hanging around, but you might be able to manage them more easily. Link to comment Share on other sites More sharing options...
Craig Hopson Posted May 4, 2012 Author Share Posted May 4, 2012 ok, so a class would be a group of functions? and how would i call the functions like this <a href="<? MyFunction();?>">TEST</a> Link to comment Share on other sites More sharing options...
Craig Hopson Posted May 21, 2012 Author Share Posted May 21, 2012 i think i've found a way to do this but not shore if its OK to do it this way so heres the code <html><head></head><body>Hello this is a test <p><a href="index.php?x=menu1">menu1</a> <a href="index.php?x=menu2">menu2</a> <?if($_GET['x'] == menu1){echo 'menu1'; }if($_GET['x'] == menu2){echo 'menu2'; } ?> </body></html> Link to comment Share on other sites More sharing options...
Guest So Called Posted May 21, 2012 Share Posted May 21, 2012 How about: if (isset($_GET['x'])) switch ($_GET['x']) { case 'menu1': echo 'menu1'; break; case 'menu2': echo 'menu2'; break; default: // whatever} 1 Link to comment Share on other sites More sharing options...
Craig Hopson Posted May 21, 2012 Author Share Posted May 21, 2012 Why switch & case like that and not my way????? What is the differance??? Link to comment Share on other sites More sharing options...
Guest So Called Posted May 21, 2012 Share Posted May 21, 2012 Fine. Just remember to use isset(), and put your character strings in quotes. Link to comment Share on other sites More sharing options...
birbal Posted May 21, 2012 Share Posted May 21, 2012 but you have quote it around. you have to check against string "menu1"if($_GET['x'] == "menu1"){your way will work too. but switch case comes when you have multiple if-else check on variable. Link to comment Share on other sites More sharing options...
Craig Hopson Posted May 21, 2012 Author Share Posted May 21, 2012 Which way is best tho Link to comment Share on other sites More sharing options...
justsomeguy Posted May 21, 2012 Share Posted May 21, 2012 It depends on your situation. If you have many comparisons on the same variable then a switch statement is typically easier to follow. 1 Link to comment Share on other sites More sharing options...
Craig Hopson Posted May 21, 2012 Author Share Posted May 21, 2012 Thanks guys Link to comment Share on other sites More sharing options...
Craig Hopson Posted May 21, 2012 Author Share Posted May 21, 2012 (edited) using this code if (isset($_GET['x'])) switch ($_GET['x']) { case 'menu1': echo 'menu1'; break; case 'menu2': echo 'menu2'; break; default: echo 'menu';} if $_GET['x'] = null then i want it to auto go to default automaticly how would i do this? SORTED IT USE ELSE STATMENT!!! Edited May 21, 2012 by Craig Hopson Link to comment Share on other sites More sharing options...
Guest So Called Posted May 21, 2012 Share Posted May 21, 2012 Exactly! 1 Link to comment Share on other sites More sharing options...
Craig Hopson Posted May 22, 2012 Author Share Posted May 22, 2012 ok next problem using function menu (){echo 'menu';}function menu2 ()echo 'menu2';}if (isset($_GET['x'])) switch ($_GET['x']) { case 'menu1': menu(); break; case 'menu2': menu2(); break; default: echo 'menu';} how do i change between functions dynamicly like with AJAX or JAVASCRIPT??? Link to comment Share on other sites More sharing options...
birbal Posted May 22, 2012 Share Posted May 22, 2012 can you elaborate more? you want to execute a functiion only with ajax? Link to comment Share on other sites More sharing options...
birbal Posted May 22, 2012 Share Posted May 22, 2012 can you elaborate more? you want to execute a functiion only with ajax? Link to comment Share on other sites More sharing options...
Craig Hopson Posted May 22, 2012 Author Share Posted May 22, 2012 function menu (){echo 'menu';}function menu2 ()echo 'menu2';}if (isset($_GET['x'])) switch ($_GET['x']) { case 'menu1': menu(); break; case 'menu2': menu2(); break; default: echo 'menu';}echo '<a href="index.php?x=menu1">Menu1</a>';echo '<a href="index.php?x=menu2">Menu2</a>'; this is what im using but rather than using href use AJAX so it dont reload the page each time i just swaps the function over Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now