Jump to content

Erm... Complicated.


Darkness

Recommended Posts

Hi. Not sure what to name the title for this, really. So, uh, I was wondering how you make URLs such as http://mywebsite.com/forum.php?fid=3, or something similar (the fid=3 part is what I need to know how to do). My friend said it had something to do with server scripting or Javascript, so, I just posted it here, as I'm not quite sure where this would belong.Thanks.

Link to comment
Share on other sites

Hi. Not sure what to name the title for this, really. So, uh, I was wondering how you make URLs such as http://mywebsite.com/forum.php?fid=3, or something similar (the fid=3 part is what I need to know how to do). My friend said it had something to do with server scripting or Javascript, so, I just posted it here, as I'm not quite sure where this would belong.Thanks.
There are a couple of ways to do this. Firstly, if you only have a couple of outcomes that you want to occur, or if you're controlling the outcome (using them as links and such) then you can define them simply in php.
if ($link == "home") {include ();}

This would mean when page.php?link=home is accessed, the code between {} is called, in this case, include().This is how I would do it, if you only had a couple of outcomes..

if ($link == "home") {include ();} elseif ($link == "work") {echo "work";} elseif ($link == "") {echo "no ?link specified";} else {echo "Invalid ?link specified";}

$link == "" means that no ?link is specified, so any code between the {} corresponding with that, would happen if they directly accessed the page itself, eg, http://yourdomain.com/thispage.phpelse {} means that if the ?link they specify isnt empty, or doesnt match a $link you have specified, this code will be called upon..There is another way to do things, which is a bit more PHP complex, but is alot easier when you have a lot of outcomes..

if(isset($_GET['id'])){$query = "your mysql query WHERE id = '{$_GET['id']}'";$result = mysql_query($query);while ($row = mysql_fetch_array( $result )) {// in here is the code that would be executed, specific for each query result, for example..echo "You just typed in:";echo $row['id'];echo "<br />This item, has the name:";echo $row['name'];echo "how cool is that!";

This is for when you have a lot of outcomes, change query to your mysql query.. $row['']; must match your mysql databases column names, so $row['name']; would be the column `name` from your mysql database, when the records ID matches ?id=Hope this helps :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...