Jump to content

Erm... Complicated.


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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...