homepage Welcome to WebmasterWorld Guest from 54.198.148.191
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Accredited PayPal World Seller

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
url help
how do I get it to say index.php?do=home:1
PokeTech




msg:3658800
 9:45 pm on May 25, 2008 (gmt 0)

Say this is a file named index.php:

<?php
function viewdoSection($do)
{
switch($do) {
case 'home':
$section = 'home';
break;
default:
$section = false;
break;
}
return $section;
}

if(!empty($_GET['do']))
$section = viewdoSection($_GET['do']);

if (isset($section) && $section == 'home') {
print "<p>Print out some home section text.</p>";

} else {
print "<p>Just Information that gets shown if all other do checks fail.</p>";
}

?>

I can get the index.php?do=home to work but then is it possible to go even further so the url might look something like this: index.php?do=home:1 or index.php?do=home:2 or something like that? Cause I'm trying to draw information from the sql database and I have like 3 pages in one already but I want to be able to display different things one each the home:1 and home:2 page. I think this is called urlencode(); but I don't really understand it.

If anyone understands this can you please help me!

 

TheAlbinoEthiopian




msg:3658804
 9:50 pm on May 25, 2008 (gmt 0)

I don't think you can use colons in urls outside of the http:// part, firefox filters it out of the href. Anyway, why don't you just use another variable? Like ?do=home&sub=1?

PokeTech




msg:3658806
 9:54 pm on May 25, 2008 (gmt 0)

how do you do that?

EDIT: examples greatly appreciated

[edited by: PokeTech at 9:55 pm (utc) on May 25, 2008]

yumigator




msg:3658818
 10:33 pm on May 25, 2008 (gmt 0)

If you had the url given as index.php?do=home&sub=1 you could use the variables $_GET['home'] and $_GET['sub'] in your script.

<?php 

function viewdoSection($do) {
switch ($do) {
case 'home':
$section = 'home';
break;
default:
$section = FALSE;
break;
}
return $section;
}

if (isset($_GET['do']) && !empty($_GET['do'])) {
viewdoSection($_GET['do']);
if ($section == 'home') {
if (isset($_GET['sub']) && !empty($_GET['sub'])) {
switch ($_GET['sub']) {
// handle $_GET['sub'] however you wish
}
} else {
echo('some error message');
}
} else {
echo('some error message');
}
}

?>

I didn't see anything in your code that would handle the other part of the URL, but this should give you a general idea.

If you absolutely need the type of URL your originally asked about, a comma instead of a colon would work very well. I personally prefer slashes for the search-engine-friendliness.

PokeTech




msg:3658831
 10:57 pm on May 25, 2008 (gmt 0)

For some reason I keep getting the "some error message" why is that? I really don't know much about $_GET so thats why I'm asking.

yumigator




msg:3658842
 11:41 pm on May 25, 2008 (gmt 0)

A stupid mistake on my part. Change "viewdoSection($_GET['do']);" to "$section = viewdoSection($_GET['do']);" If everything works correctly, you should see a blank page (since there is no logic processing $_GET['sub']: all that is there is a comment.

Anyway, that was just an example; it probably won't help you much in the way of getting some working code. $_GET is quite simple. If you give the URL as index.php?foo=bar the variable $_GET['foo'] will be set to "bar" in your script.

For multiple values: index.php?foo=bar&yes=no would set $_GET['foo'] to "bar" and $_GET['yes'] to "no".

You can use a $_GET variable as you would any other variable. Knowing that, you should be able to apply your knowledge of control structures to getting exactly the effect you want.

jianliangwang




msg:3663586
 11:59 am on May 31, 2008 (gmt 0)

$do = $_GET['do'];
$do =explode(":",$do);
$do = $do[1];

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved