Forum Moderators: coopster

Message Too Old, No Replies

GET values from URL

         

Saint Honore

3:04 pm on Aug 10, 2007 (gmt 0)

10+ Year Member



Hello everyone,

I have been working on a script that has select option however the name is not an array. EG:

<SELECT NAME="list21" MULTIPLE SIZE=10 onDblClick="moveSelectedOptions(this.form['list21'],this.form['list11'],false)">

When i click on submit all the selected option in the select box is passed in URL as iam using get. But I when i say

foreach ($_GET as $key => $value)
{
print "$key has a value of $value";
}
it only prints me the last value of the select box.

can someone please help me in getting this done, Iam at tight schedule, i did all teh left-right to get this but no luck

please help....

warm Regards

PHP_Chimp

3:34 pm on Aug 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



how are you selecting all the options? As a select statement usually returns 1 option. However with the multiple bit you would have to hold control (or whatever other key on mac's) and select. Why not use checkboxes as most people will not be able to cope with multiple selects.

However - back to your problem -

have you tried to look at all of the $_GET variables to see what is getting passed over?
<pre>
<?php print_r($_GET);?>
</pre>
I am assuming that you are only getting 1 value sent through as there is only 1 value getting passed from the select statement, as that is the usual behaviour.

Scally_Ally

4:23 pm on Aug 10, 2007 (gmt 0)

10+ Year Member



if you are using a multi select box then it has to be declared as an array in html.

<SELECT NAME="list21[]" MULTIPLE SIZE=10 onDblClick="moveSelectedOptions(this.form['list21'],this.form['list11'],false)">

you can then use it as an array in PHP - one more thing, it would be better to post the form as you cant send an array on the query string.

Ally

[edited by: Scally_Ally at 4:24 pm (utc) on Aug. 10, 2007]

whoisgregg

4:24 pm on Aug 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The name of the select needs square brackets at the end:

<select name="list21[]" multiple="multiple" size="10">

Added: Ally beat me to it. :)

Saint Honore

7:31 am on Aug 11, 2007 (gmt 0)

10+ Year Member



Hello Friends,

I don't want to make that select name as array by adding square brackets. (list21[])

Iam getting the values as index.php?list21=123&list21=222&list21=xyz in the url when i clk on submit.

when i say
$list_value = $_GET['list21']
echo $list_value
I get only xyz.

As mentioned earlier I have even tried with foreach but no luck.

Warm Regards

Saint Honore

1:40 pm on Aug 11, 2007 (gmt 0)

10+ Year Member



Hello Friends,

Is there anyone who can help me out there please.....?

Warm Regards

jatar_k

1:46 pm on Aug 11, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



if they all have the same name then you should only get the last value, the var gets corrupted, try dumping the GET and see what is in there

echo '<p>GET vars: <pre>';
print_r($_GET);
echo '</pre>';

Saint Honore

2:45 pm on Aug 11, 2007 (gmt 0)

10+ Year Member



Hello Admin,

Thanks for the quick and prompt reply,
I tried printing the eacho and it only give me the last value. Kindly suggest.

Warm Regards

jatar_k

3:02 pm on Aug 11, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



they will either have to have different variable names or you will have to use the syntax as was mentioned by other members in the thread

oxidetones

10:11 pm on Aug 11, 2007 (gmt 0)

10+ Year Member



Hey Jatar, I have a related question to your last question, as I have a similar issue...

I have checkboxes (with []) and get the parameters sent to the url of the following page with the same name. How is it possible to give them different names within one form?

jatar_k

10:28 pm on Aug 11, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



are you using POST or GET? Not sure how this works when you use the array notation and GET, easy enough using POST though.

checkboxes can be named individually as well

coopster

10:29 pm on Aug 11, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Examples of doing so can be found on the PHP and HTML [php.net] manual page.

oxidetones

11:50 pm on Aug 11, 2007 (gmt 0)

10+ Year Member



I am using GET. I cant name the options differently as the list of checkboxes is called from a database (while loop).

Ive tried to explain my problem on this thread: [webmasterworld.com...]

whoisgregg

1:58 pm on Aug 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you are sending the values using get and have a URL that looks like this:

 index.php?list21=123&list21=222&list21=xyz

Then you can manually parse the values out of the $_SERVER['REQUEST_URI'] value. You'd do something along these lines...

if(strpos($_SERVER['REQUEST_URI'], '?') !== false){
list($file, $query) = explode('?', $_SERVER['REQUEST_URI']);
$pairs = explode('&', $query);
foreach($pairs as $p){
$name = $val = '';
list($name, $val) = explode('=', $p);
if($name=='list21'){
$list21[] = $val;
}
}
}
echo '<pre>'; print_r($list21); echo '</pre>';