Jump to content


PHP Dropdown menu


3 replies to this topic

#1 l3lueMage

    Wanna Be Moderator

  • Publishing Betazoids
  • PipPipPipPip
  • 4,596 posts
  • Gender:Male
  • Location:San Francisco Bay Area

Posted 04 May 2006 - 02:54 AM

Actually, forget the title, I am wondering how to make it so if you say something like
<a href="sample.php?choice1">click</a>

It will do whatever choice1 may be on the next page, so theres like if and else statements that execute, seeing what was put in the URL...

Edited by l3lueMage, 04 May 2006 - 03:09 AM.


#2 Indigo

    Official Alien

  • Members
  • PipPipPip
  • 617 posts
  • Gender:Male
  • Location:Trondheim, Norway
  • Interests:Computing in general, especially design and programming of all kinds.

Posted 04 May 2006 - 04:31 AM

Does this help?
This sort of thing should be answered other places in the forums too, but I couldnīt find any other links.

Personally, I use something like this:

<?php
$allowed = array('sample1', 'sample2');
$page = (isset($_GET['page'])) ? $_GET['page'] : īWelcome;
if (in_array($page, $allowed)) {
	include("$page.php");
}
		
else {
	include("frontpage.php");
}
?>
		
<a href="index.php?page=sample1">Sample1</a><br />
<a href="index.php?page=sample2">Sample2</a><br />

This script ainīt perfect, and even I donīt understand the part where it says "Welcome" and such (but I donīt know how to remove it).
What it basically does is to get the page and display it if itīs in the array. If thereīs no page selected, it will display frontpage.php, and if somebody tries to do something like index.php?page=http://www.mypage.com/evilscript.php, they will also be redirected to frontpage.php.

#3 syphon

    Young Padawan

  • Members
  • Pip
  • 57 posts

Posted 04 May 2006 - 08:11 PM

or you could, if you wanted a more static approach do...
<?php
//next page, url is sample.php?choice1

if(isset($_GET['choice1']))
{
	 echo $content;
} else {
	 echo $error
}
?>


#4 l3lueMage

    Wanna Be Moderator

  • Publishing Betazoids
  • PipPipPipPip
  • 4,596 posts
  • Gender:Male
  • Location:San Francisco Bay Area

Posted 06 May 2006 - 01:59 AM

Thanks guys, it helped :P

Edited by l3lueMage, 06 May 2006 - 01:59 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users