...

View Full Version : how to $_GET multiple values



gilgalbiblewhee
04-21-2011, 09:07 PM
Is there an easy way to $_GET multiple values from the url:

?type=forforum&no=0&source0=tr&btitle0=Matthew&no=1&source1=kjv&btitle1=Matthew&checkresult0=1&checkresult1=23195
The reason I ask is because I want to add more to this later on such as:

?type=forforum&no=0&source0=tr&btitle0=Matthew&no=1&source1=kjv&btitle1=Matthew&checkresult0=1&checkresult1=23195&no=2&source2=kjv&btitle2=Matthew&checkresult2=23195&no=3...&no=4...
This is how it's interpreted so far:

$bk=isset($_GET["book".$no]) ? $_GET["book".$no] : "";
$ch=isset($_GET["chapter".$no]) ? $_GET["chapter".$no] : "";
$vs=isset($_GET["verse".$no]) ? $_GET["verse".$no] : "";
$source=isset($_GET["source".$no]) ? $_GET["source".$no] : "";
$sourceAbb=Array("kjv", "mt", "mtnv", "tr");
$SourceName=Array("King James", "Masoretic Text", "Masoretic No Vowels", "Textus Receptus");
$SourceTable=Array($dbTable3, $dbTable7, $dbTable9, $dbTable8);
for($i=0; $i<count($SourceTable); $i++){
if($source==$sourceAbb[$i]){
$sql = "SELECT * FROM ".$SourceTable[$i]." WHERE book = '".$bk."' AND chapter= '".$ch."'";
if($vs != 'all'){
$sql .= " AND verse= '".$vs."'";
}
$sql .= " ORDER BY id ASC";
//echo $sql;
}
}

oesxyl
04-21-2011, 09:20 PM
first problem:, $_GET and $_POST can't contain same value twice, for example:
using url?no=1&.....&no=6 you can have both 1 and 6 in $_GET['no'], only one of them, probably 6 because is the last one.

second problem: $_GET lenght is limited use $_POST insted, is limited too but it's limit is bigger.

you know what parameters you expect so you can build a array:


$expected = array('type' => '',
'no' => '',
'source0' => '',
'btitle0' => '',
'source1' => '',
'btitle1' => '',
'checkresult0' => '',
'checkresult1' => '',
'source2' => '',
'btitle2' => '',
'checkresult2' => ''
);

foreach($expected as $name => $value){
if(isset($_GET[$name]) && $value !== ''){
// check if $_GET[$name] is what you expect here
$expected[$name] = $_GET[$name];
}
}

// use $expected[$name] instead of $_GET[$name]



best regards

gilgalbiblewhee
04-21-2011, 09:32 PM
first problem:, $_GET and $_POST can't contain same value twice, for example:
using url?no=1&.....&no=6 you can have both 1 and 6 in $_GET['no'], only one of them, probably 6 because is the last one.

second problem: $_GET lenght is limited use $_POST insted, is limited too but it's limit is bigger.

you know what parameters you expect so you can build a array:


$expected = array('type' => '',
'no' => '',
'source0' => '',
'btitle0' => '',
'source1' => '',
'btitle1' => '',
'checkresult0' => '',
'checkresult1' => '',
'source2' => '',
'btitle2' => '',
'checkresult2' => ''
);

foreach($expected as $name => $value){
if(isset($_GET[$name]) && $value !== ''){
// check if $_GET[$name] is what you expect here
$expected[$name] = $_GET[$name];
}
}

// use $expected[$name] instead of $_GET[$name]



best regards
Ok the meaning of the $no is the number. Let's say I'm doing 3 searches then the url should show &no=0...&no=1...&no=2... Unless there's a better way of expressing this. Maybe &no=0+1+2. Or is it necessary to put this at all?
I want to be able to retrieve all the values which are numbered 0, 1, 2.
Something like this?

'source'[$no] => '',
'btitle'[$no] => '',

oesxyl
04-21-2011, 09:35 PM
Ok the meaning of the $no is the number. Let's say I'm doing 3 searches then the url should show &no=0...&no=1...&no=2... Unless there's a better way of expressing this. Maybe &no=0+1+2. Or is it necessary to put this at all?
I want to be able to retrieve all the values which are numbered 0, 1, 2
why can't you use no=3 instead and interpret this like the number of search? i mean having no=6 mean 6 searches 0, 1, 2,...,5.

best regards

gilgalbiblewhee
04-21-2011, 10:08 PM
why can't you use no=3 instead and interpret this like the number of search? i mean having no=6 mean 6 searches 0, 1, 2,...,5.

best regards
Yes but then I'm wondering how I'm going to build the url in the previous .php file. So far I have 2 searches:
http://gbgrafix.com/thewheelofgod/twotexts/

and clicking on the What To Do's For Forum Use it has to be accordingly.

Let's say if I use one search then only 1 should appear in the For Forum Use's url &no=0 or 1?

oesxyl
04-21-2011, 10:43 PM
Yes but then I'm wondering how I'm going to build the url in the previous .php file. So far I have 2 searches:
http://gbgrafix.com/thewheelofgod/twotexts/

and clicking on the What To Do's For Forum Use it has to be accordingly.

Let's say if I use one search then only 1 should appear in the For Forum Use's url &no=0 or 1?
i'm sorry but i don't understand.
If you build a search and use a select in the, with single or multiple selections, you probably need a form:



<form method="post" action="someurl">
<div>
<p>What To Do</p>
<select name="mimi" id="mimi" multiple="multiple">
<option value="0">For Forum Use</option>
<option value="1">blah blah</option>
<option value="2">geh, geh</option>
</select>
</div>
</form>


the submit will take care of sending one or more values.

http://www.onlinetools.org/tricks/using_multiple_select.php

best regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum