Jump to content

Question concerning links in php


elite_thut

Recommended Posts

I have a question  You First have to take a look at this to understand my question...Go on [url="http://newd2event.net"]this link[/url] then put your mouse on a menu element and look at where it links...It links at something like this ...[i]http://newd2event.net/index.php?id=characters[/i]or[i]http://newd2event.net/index.php?id=bosses[/i]or[i]http://newd2event.net/index.php?id=druid[/i]And when it's [color="green"]/index.php?id=this[/color]it's the same page as[color="green"]/index.php?id=that[/color]but the content(text) is differentI would like to know what it is exactly... is it just a link to a page but they make the page identical(1)?or is it the same page but with php, it changes the text (2)...[i]If the answer to my first question is (1) :[/i]How does it work exactly, how can we link it php.[i]And if the answer is (2) :[/i]How can we do that, do you know of a tutorial, or could you explain it vaguely.And by the way, I'm not new to php... I have to say I'm quite advanced (even if I don't look like...especially in this post   )So if you can explain it to me you just have to give me the main idea and I'll be fine.

Link to comment
Share on other sites

I'm doing the same thing.The index.php first fetches the ?id=this from the address, by using $id=$_GET['id']; it now knowt $id=this.I figure the entire index.php is a bunch of nested IF statements. So basically IF ($id == 'this') { load the page named 'this' from the database }Example: my (incomplete) one-page guestbook!

$pageid=$_GET['pageid'];if ($pageid == 'gastenboek') {		if ($pageid == 'write') {		if (isset($_POST['akkoord'])) {				$gnam=$_POST['gnam'];			$gmal=$_POST['gmal'];			$gdat=$_POST['date'];			$gcon=$_POST['gcon'];						if ($gnam == "" || $gmal == "" || $gcon == "") {				echo "Niet alle verplichte velden zijn ingevuld. <a href=index.php?pageid=write>opnieuw</a>";			}			else {				mysql_connect('localhost',$user,$pass);				mysql_select_db($dbas) or die( "Unable to select database");								$query="INSERT INTO gastenboek VALUES ('','gnam','gmal','gdat','gcon'";				mysql_query($query);				echo "Uw bericht is toegevoegd, dank u wel.";								mysql_close();			}		}		else {			echo "<form action=index.php?pageid=write method=post>";			$date=date('ymdHi');			$maand_array = array("januari", "februari", "maart", "april","mei", "juni", "juli", "augustus", "september","oktober", "november", "december");			$datum = date("j ") . $maand_array[date("n") - 1] . date(" Y");			echo "<table><tr><td><b>Naam</b><td><b>E-mailadres</b></tr><tr><td><input type=text name=gnam size=30><td> <input type=text name=gmal size=40></tr></tr><table><br><b>Datum:</b>$datum<input type=hidden name=gdat value=$date>";			echo "<br><textarea rows=20 cols=70 name=gcon></textarea><br><input type=submit name=akkoord value='voeg toe'>";		}	}	else {		mysql_connect('localhost',$user,$pass);		mysql_select_db($dbas) or die( "kan database niet vinden.");				$query="SELECT * from GASTENBOEK ORDER BY date ASC";		$result=mysql_query($query);				$num=mysql_num_rows($result);				$i=1;		while($i < $num) {			$name=mysql_result($result,$i,"gnam");			$mail=mysql_result($result,$i,"gmal");			$date=mysql_result($result,$i,"gdat");			$gcon=mysql_result($result,$i,"naam");			$i++;			echo "";		}	}}if ($pageid='somethingelse') {     \\run some script}

So when I link to index.php?pageid='gastenboek' it'll execute the script assigned to the $pageid=gastenboek.Hope this makes things clear.Welcome to the forums dude :)

Link to comment
Share on other sites

Just to add a little more to yoshida's reply...To make it simple and seperate the nested IF conditions from your main code, you can try FUSEBOX approach. the idea is like this....create a seperate php file [say handler.php] this will contain all the if conditions based on the query strings you will use, include this file in the index.php and you can easily change the content. every page request must go through handler.php.

Link to comment
Share on other sites

or even easier, use a switch statement:

switch  ($_GET['id']) {case 'this' :echo "the code for page this";break;case 'that' :echo "the code for page that";break;default :echo 'default page here';break;}

that is equal to this:

if($_GET['id'] == 'this'){echo 'the code for page this';}elseif($_GET['id'] == 'that'){echo "the code for page that";}else{echo "the default page";}

go here for more info: http://us3.php.net/switch

Link to comment
Share on other sites

Seems like I'm not that good with PHP as I thought :) I'm having one chunky 300 line index.php with close to 10 pageid scripts. Thought of calling it 'eggshell', since nested if's hatch solutions (geekhumor).

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...