Forum Moderators: coopster

Message Too Old, No Replies

Help needed with querystrings

         

MaticooL

11:38 am on Mar 19, 2006 (gmt 0)

10+ Year Member



Hi!
I am using now a php script to pass querystrings. The code is below, however the problem is that I dont know how to add a second querystring for included file. For example how to make it [somesitename.com...]
Please help me.

Thanks in advance!

<?php

if(isset($_GET['page'])){

switch($_GET['page']) {
case 'home' :
include 'news.php';
break;

case 'products' :
include 'products.inc.php';
break;

case 'contact' :
include 'contact.inc.php';
break;

case 'about' :
include 'about.inc.php';
break;

case 'links' :
include 'links.inc.php';
break;

}
}
else {
include('news.php');
}
?>

Birdman

2:51 pm on Mar 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



We need a bit more info to help. You do not show the code that builds the link and what are you going to do with the "$num" variable?

MaticooL

3:15 pm on Mar 19, 2006 (gmt 0)

10+ Year Member



This code makes links like that:

[somesitename.com...]
[somesitename.com...]
[somesitename.com...]
[somesitename.com...]
etc...

But the thing that I dont know is what script do I need to add to the one I have to make querystring for example:

[somesitename.com...]

Birdman

4:06 pm on Mar 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The code you show doesn't 'make' the links. It evaluates the link that opened the script. You need to first edit the script that actually 'creates' the links, then you can edit the script above to look for/use the extra variable.

I hope that makes some sense :)

MaticooL

4:36 pm on Mar 19, 2006 (gmt 0)

10+ Year Member



It doesn't make any sense actually. Do you have any IM? For example MSN so I can actually explain my problem?

Birdman

5:10 pm on Mar 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



No need for IM, you can explain your problem here so others can also benefit.

You said:

I am using now a php script to pass querystrings. The code is below,

The code you posted does not pass a querystring. It evaluates the querystring that was already passed in. You are leaving something out.

MaticooL

5:23 pm on Mar 19, 2006 (gmt 0)

10+ Year Member



You still dont understand, the code wokrs well! I cant explain it here...

grandpa

6:23 pm on Mar 19, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I think this is what you might be looking for. In order to test for multiple querystrings first I added another if-condition, then I concatenated the multiple strings into $testval, then performed the switch testing with the $testval variable. If only a single string is passed, ie, page, then the second set of conditions will apply. I added a default to that group. Finally, if no querystring is passed then the default is your final else condition.

I hope that's what you wanted. I modified this to echo the values, you'll need to make changes for your include files.

<?php

if(isset($_GET['page']) && isset($_GET['num'])) {
$testval = $_GET['page'];
$testval .= $_GET['num'];
switch($testval) {
case 'home1':
echo 'home 1.php';
break;

case 'home2':
echo 'home 2.php';
break;

case 'home3':
echo 'home 3.php';
break;

}
}

else if(isset($_GET['page'])){

switch($_GET['page']) {
case 'home' :
echo 'home.php';
break;

case 'products' :
echo 'products.inc.php';
break;

case 'contact' :
echo 'contact.inc.php';
break;

case 'about' :
echo 'about.inc.php';
break;

case 'links' :
echo 'links.inc.php';
break;

default:
echo 'Please check your selection';
break;

}
}
else {
echo 'news.php';
}
?>

MaticooL

9:20 am on Mar 21, 2006 (gmt 0)

10+ Year Member



Thanks, I'll try that today =)

MaticooL

9:50 am on Mar 23, 2006 (gmt 0)

10+ Year Member



Hm, I still cant see anything if I go to index.php?page=home&num=home1

grandpa

11:30 am on Mar 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



num=home1

Maybe try it with num=1

The variable value of 'home1' is derived from both of the individual parameters. If you set num=home1 then your variable would end up being homehome1.