Jump to content

Basic menu in few files


Craig Hopson

Recommended Posts

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 :good:

Link to comment
Share on other sites

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

  • 3 weeks later...

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

Guest So Called

How about:

if (isset($_GET['x'])) switch ($_GET['x']) { 	case 'menu1':	echo 'menu1';			break; 	case 'menu2':	echo 'menu2';			break; 	default:	// whatever}

  • Like 1
Link to comment
Share on other sites

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

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 by Craig Hopson
Link to comment
Share on other sites

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

can you elaborate more? you want to execute a functiion only with ajax?

Link to comment
Share on other sites

can you elaborate more? you want to execute a functiion only with ajax?

Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...