php Help?
Author
Discussion

MyNameIsMud

Original Poster:

50 posts

247 months

Saturday 11th March 2006
quotequote all
I'm looking to write some code that will display content (from an XML source) depending on whats in the URL/Address Bar. An example of this could be www.asite.com/fetch.php?=cars

Does this make any sense? Basically a searchbox on another page would send the user to a page with the url above, the page shown would pull XML source according to the bit following the '?'

Can anyone help, i've set up a phpBB board, but this is way beyond me.

docevi1

10,430 posts

278 months

Saturday 11th March 2006
quotequote all
all you need is the following code:

require($_GET['parameterName']."htm";

where parameter name is "pageName?parameterName=something" and .htm is the extension you want. Wrap that in PHP tags and jobs a goodun.

edit: You may want some rudimentary validation on there mind, this is what I use on my page:
<?PHP

$page = "";
if(isSet($_GET['menu']))
if($_GET['menu'] == "pic"
$page = "pic";
if($_GET['menu'] == "marlinLinks"
$page = "links";
else if(isSet($_GET['menu']) && !isSet($_GET['type']))
$page = $_GET['menu'];
else if(isSet($_GET['menu']) && isSet($_GET['type']))
$page = $_GET['menu']."/".$_GET['type'];
else
$page = "index";

$page = "pages/".$page.".php";

if(file_exists($page))
require_once($page);
else
echo ("File Not Found: ".$page. " ". $_GET['menu']);
?>

>> Edited by docevi1 on Saturday 11th March 18:07

MyNameIsMud

Original Poster:

50 posts

247 months

Saturday 11th March 2006
quotequote all
You legend - i'll give that a go and report back!

Thanks.

MyNameIsMud

Original Poster:

50 posts

247 months

Saturday 11th March 2006
quotequote all
And no surprise, I couldn't get it to work (my coding skills no doubt)!

Got this error:
Parse error: syntax error, unexpected T_VARIABLE in /hsphere/local/home/test.php on line 6

Below is also a better example of what i'm after:

google.co.uk/search?hl=en&q=test&meta=

"test" being the term for which I wish to display data for on the page.

Can anyone help such a useless programmer as myself?


zoidberg

8,883 posts

312 months

Sunday 12th March 2006
quotequote all
MyNameIsMud said:
And no surprise, I couldn't get it to work (my coding skills no doubt)!

Got this error:
Parse error: syntax error, unexpected T_VARIABLE in /hsphere/local/home/test.php on line 6

Below is also a better example of what i'm after:

google.co.uk/search?hl=en&q=test&meta=

"test" being the term for which I wish to display data for on the page.

Can anyone help such a useless programmer as myself?




<?php

if (isset($_GET["q"]))
{
$contentToDisplay = $_GET["q"];
}
else
{
echo "Parameter not set";
}

?>

EDIT: Obviousl though this wouldn't work if the page you were looking at was google.co.uk!

>> Edited by zoidberg on Sunday 12th March 16:59

MyNameIsMud

Original Poster:

50 posts

247 months

Sunday 12th March 2006
quotequote all
Thanks, that's great. Now, if the parameter isn't set, can I display a different page to one where the parameter is set? Is that easy to do?

docevi1

10,430 posts

278 months

Sunday 12th March 2006
quotequote all
<?
$pa = ""
if(isset($_GET['p'])
{
$pa = $_GET['p']
}
else
{
$pa = "default page"
}
require($pa)

?>