• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

query string question

KapTinKiRk

New Member
I'm trying to edit a script so that I can use the query string to decide which directory the script will read. But the thing is I want to do it with numbers.

script.cgi?sectionID=2&id=pagename

So then '2' will equal to a path name...

/path/to/whatever/

and the id query is the name of the file. I've gotten it to work when I only use the id string, which is pretty simple. But my big problem is, how do I go about telling the script where to go for each number?

1 = "/path/to/whatever"
2 = "/path/to/somewhere"

I did the following...

Code:
$sectionID = "$INPUT{'sectionID'}";
$section = "home/" if ($sectionID eq '1');

and it works, but when I need to add the ones for 2, 3, 4 etc. etc.

Code:
$sectionID = "$INPUT{'sectionID'}";
$section = "home/" if ($sectionID eq '1');
$section = "movies/" if ($sectionID eq '2');
$section = "movies/previews/" if ($sectionID eq '3');

..it gives errors, anyone know how to do this properly? Any help is appreciated. If I didn't explain it enough, then tell me ;)
 
It would help if you posted what the errors are... does it work but doesn't give the desired results, or does it come up with a error code?

At first glance, it looks ok, but then again im working on assembly for class so my mind is astray :)

[Edited by cds on 11-05-2000 at 09:59 PM]
 
Originally posted by KapTinKiRk
I'm trying to edit a script so that I can use the query string to decide which directory the script will read. But the thing is I want to do it with numbers.

script.cgi?sectionID=2&id=pagename

So then '2' will equal to a path name...

/path/to/whatever/

and the id query is the name of the file. I've gotten it to work when I only use the id string, which is pretty simple. But my big problem is, how do I go about telling the script where to go for each number?

1 = "/path/to/whatever"
2 = "/path/to/somewhere"

I did the following...

Code:
$sectionID = "$INPUT{'sectionID'}";
$section = "home/" if ($sectionID eq '1');

and it works, but when I need to add the ones for 2, 3, 4 etc. etc.

Code:
$sectionID = "$INPUT{'sectionID'}";
$section = "home/" if ($sectionID eq '1');
$section = "movies/" if ($sectionID eq '2');
$section = "movies/previews/" if ($sectionID eq '3');

..it gives errors, anyone know how to do this properly? Any help is appreciated. If I didn't explain it enough, then tell me ;)

Instead of using this method for your if else statments:
Code:
$sectionID = "$INPUT{'sectionID'}";
$section = "home/" if ($sectionID eq '1');
$section = "movies/" if ($sectionID eq '2');
$section = "movies/previews/" if ($sectionID eq '3');
You should probably use the standard format:

Code:
$sectionID = "$INPUT{'sectionID'}";
if($sectionID eq '1'){
  $section = "home/";
}
elsif ($sectionID eq '2'){
  $section = "movies/";
}
elsif ($sectionID eq '3'){
  $section = "movies/previews/";
}
You should also probably use the numerical comparison instead of the literal comparison. So the code should be like this:

Code:
$sectionID = "$INPUT{'sectionID'}";
if($sectionID == 1){
  $section = "home/";
}
elsif ($sectionID == 2){
  $section = "movies/";
}
elsif ($sectionID == 3){
  $section = "movies/previews/";
}
 
Dont worry about it(but thanks)...we've solved his problem :)

The prob was that you couldn't expect an include script to execute its code...so just put in a sub, and execute that...simple :)
 
I really admire your work Grant...especially with your news system...

I hope that you will continue to post in the future...we will all be better off for it! :)
 
Originally posted by KapTinKiRk
yea, got it working, thanks cds... surprising to see you here Grant ;)
Glad you got it working. Yeah, I try to stop by this board when I get a chance :)
Originally posted by cds
I really admire your work Grant...especially with your news system...

I hope that you will continue to post in the future...we will all be better off for it! ;)
Thanks for the compliments. I will continue to try and post on this board whenever I have the time. Thanks.
 
Back
Top