array in $_GET ...

i'll try to be short ... i have this in html :

<select name="OS[]" size="5">
   <option value="0" selected>Please select one or more...</option>
   <option value="1">Windows</option>
   <option value="2">Mac OS X</option>
   <option value="3">Linux</option>
</select>

and i want to echo the values from this simple list (OS), i mean array 
from $_GET array ...

i did this:

foreach($_GET as $i => $val)
     echo $i . ": " . $val . "<br>";

but, it only echoes out OS: Array ...

and this: echo $_GET['OS'][1]."<br>\n"; but it is wrong ...

how to extract values from OS array inside te GET ? please help ...
0
dude.j (9)
6/16/2006 11:47:03 AM
comp.lang.php 32612 articles. 0 followers. Post Follow

8 Replies
170 Views

Similar Articles

[PageSpeed] 4
dude wrote:

> i'll try to be short ... i have this in html :
> 
> <select name="OS[]" size="5">
>    <option value="0" selected>Please select one or more...</option>
>    <option value="1">Windows</option>
>    <option value="2">Mac OS X</option>
>    <option value="3">Linux</option>
> </select>
> 
> and i want to echo the values from this simple list (OS), i mean array
> from $_GET array ...
> 
> i did this:
> 
> foreach($_GET as $i => $val)
>      echo $i . ": " . $val . "<br>";
> 
> but, it only echoes out OS: Array ...
> 
> and this: echo $_GET['OS'][1]."<br>\n"; but it is wrong ...
> 

> how to extract values from OS array inside te GET ? please help ...

Hi,

Your select is not an array, but a simple value, since only 1 can be 
selected.
So if you want to know what was selected, just use:
<select name="OS" size="5">

and from PHP: $_GET["OS"] 

Of course this means the method of the form was GET and not POST, in which 
case you should use $_POST["OS"]

I think you are confusing checkboxes with select.
For checkboxes you can use:
<input type="checkbox" name="myval[]" value="1">1<br>
<input type="checkbox" name="myval[]" value="2">2<br>
<input type="checkbox" name="myval[]" value="3">3<br>

then from PHP: 
$myvalArr = $_POST["myval"];

Regards,
Erwin Moller


0
6/16/2006 11:57:46 AM
"dude" <dude.j@gmail.com> wrote in message 
news:e6u5nn$3g3$1@ss408.t-com.hr...
> i'll try to be short ... i have this in html :
>
> <select name="OS[]" size="5">
>   <option value="0" selected>Please select one or more...</option>
>   <option value="1">Windows</option>
>   <option value="2">Mac OS X</option>
>   <option value="3">Linux</option>
> </select>
>
> and i want to echo the values from this simple list (OS), i mean array 
> from $_GET array ...
>
> i did this:
>
> foreach($_GET as $i => $val)
>     echo $i . ": " . $val . "<br>";


try:
foreach($_GET['OS'] as $i => $val)
    echo $i . ": " . $val . "<br>";

By the way, I think you're missing the attribute MULTIPLE from the select if 
you want to be able to select multiple items. It should be
<select name="OS[]" size="5" multiple>

or if you're using xhtml,
<select name="OS[]" size="5" multiple="multiple">



-- 
"ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk
spam@outolempi.net | Gedoon-S @ IRCnet | rot13(xvzzb@bhgbyrzcv.arg) 


0
spam4297 (354)
6/16/2006 12:04:30 PM
Erwin Moller wrote:
> dude wrote:
> 
> 
>>i'll try to be short ... i have this in html :
>>
>><select name="OS[]" size="5">
>>   <option value="0" selected>Please select one or more...</option>
>>   <option value="1">Windows</option>
>>   <option value="2">Mac OS X</option>
>>   <option value="3">Linux</option>
>></select>
>>
>>and i want to echo the values from this simple list (OS), i mean array
>>from $_GET array ...
>>
>>i did this:
>>
>>foreach($_GET as $i => $val)
>>     echo $i . ": " . $val . "<br>";
>>
>>but, it only echoes out OS: Array ...
>>
>>and this: echo $_GET['OS'][1]."<br>\n"; but it is wrong ...
>>
> 
> 
>>how to extract values from OS array inside te GET ? please help ...
> 
> 
> Hi,
> 
> Your select is not an array, but a simple value, since only 1 can be 
> selected.
> So if you want to know what was selected, just use:
> <select name="OS" size="5">
> 
> and from PHP: $_GET["OS"] 
> 
> Of course this means the method of the form was GET and not POST, in which 
> case you should use $_POST["OS"]
> 
> I think you are confusing checkboxes with select.
> For checkboxes you can use:
> <input type="checkbox" name="myval[]" value="1">1<br>
> <input type="checkbox" name="myval[]" value="2">2<br>
> <input type="checkbox" name="myval[]" value="3">3<br>
> 
> then from PHP: 
> $myvalArr = $_POST["myval"];
> 
> Regards,
> Erwin Moller

thnx, but it is not about checkboxes ... this works fine with checkboxes 
  ... not with list :)
0
dude.j (9)
6/16/2006 12:24:21 PM
> try:
> foreach($_GET['OS'] as $i => $val)
>     echo $i . ": " . $val . "<br>";
> 
> By the way, I think you're missing the attribute MULTIPLE from the select if 
> you want to be able to select multiple items. It should be
> <select name="OS[]" size="5" multiple>
> 
> or if you're using xhtml,
> <select name="OS[]" size="5" multiple="multiple">

i did set multiple, and the foreach and the echo result is:
if all the items in the list are selected :
	0: 1
	1: 2
	2: 3
	3: 3

if second selected then the echo will be: 0: 1

ok, i can work this way, but can it echo values i mean selected string,
like Windows, Linux, ... , not 0:1, 0:2, etc ...
is it possible ?
eccept if ... or switch condition

		foreach($_GET['OS'] as $i => $val)
			if($i == 0 && $val == 1)
				echo "Windows <br>";
			if($i == 0 && $val == 2)
				echo "Linux <br>";
			... etc

this is too complicated, what if i have 40 items in the list :)

			


0
dude.j (9)
6/16/2006 12:34:13 PM
dude wrote:
>> try:
>> foreach($_GET['OS'] as $i => $val)
>>     echo $i . ": " . $val . "<br>";
>>
>> By the way, I think you're missing the attribute MULTIPLE from the 
>> select if you want to be able to select multiple items. It should be
>> <select name="OS[]" size="5" multiple>
>>
>> or if you're using xhtml,
>> <select name="OS[]" size="5" multiple="multiple">
> 
> i did set multiple, and the foreach and the echo result is:
> if all the items in the list are selected :
>     0: 1
>     1: 2
>     2: 3
>     3: 3
> 
> if second selected then the echo will be: 0: 1
> 
> ok, i can work this way, but can it echo values i mean selected string,
> like Windows, Linux, ... , not 0:1, 0:2, etc ...
> is it possible ?
> eccept if ... or switch condition
> 
>         foreach($_GET['OS'] as $i => $val)
>             if($i == 0 && $val == 1)
>                 echo "Windows <br>";
>             if($i == 0 && $val == 2)
>                 echo "Linux <br>";
>             ... etc
> 
> this is too complicated, what if i have 40 items in the list :)
> 
>            
> 
> 

Why are you using 1, 2, 3, etc. when you want Windows, Linux, etc.?

Perhaps this little example will help:
<?php
if( isset($_GET['OS']) ) {
	foreach( $_GET['OS'] as $key => $value) {
		printf("Selected %s<br>\n", $value);
	}
}
?>
<html>
<head></head>
<body>
<form action="test.php" method="GET">
<select name="OS[]" size="5" multiple>
<option>Windows</option>
<option>Linux</option>
</select>
<input type="submit">
</form>
</body>
</html>

-david-


0
6/16/2006 1:04:43 PM
"dude" <dude.j@gmail.com> wrote in message 
news:e6u8g5$aau$1@ss408.t-com.hr...
>> try:
>> foreach($_GET['OS'] as $i => $val)
>>     echo $i . ": " . $val . "<br>";
>>
>> By the way, I think you're missing the attribute MULTIPLE from the select 
>> if you want to be able to select multiple items. It should be
>> <select name="OS[]" size="5" multiple>
>>
>> or if you're using xhtml,
>> <select name="OS[]" size="5" multiple="multiple">
>
> i did set multiple, and the foreach and the echo result is:
> if all the items in the list are selected :
> 0: 1
> 1: 2
> 2: 3
> 3: 3
>
> if second selected then the echo will be: 0: 1
>
> ok, i can work this way, but can it echo values i mean selected string,
> like Windows, Linux, ... , not 0:1, 0:2, etc ...
> is it possible ?
> eccept if ... or switch condition
>
> foreach($_GET['OS'] as $i => $val)
> if($i == 0 && $val == 1)
> echo "Windows <br>";
> if($i == 0 && $val == 2)
> echo "Linux <br>";
> ... etc
>
> this is too complicated, what if i have 40 items in the list :)
>
>
>
>

Looks like you're overcomplicating things.
Just change the options to pass the string instead of an index (unless you 
need the indes for something else):

<select name="OS[]" size="5" multiple="multiple">
   <option value="" selected>Please select one or more...</option>
   <option value="Windows">Windows</option>
   <option value="Mac OS X">Mac OS X</option>
   <option value="Linux">Linux</option>
</select>

Then
$myarray = $_GET['OS'];
will then give you an array of the selected Strings

cheers,
ED


0
ed9622 (19)
6/16/2006 1:05:02 PM
Thank you all ! I'm grateful. This works perfect!

Looks like I was overcomplicating things :)
0
dude.j (9)
6/16/2006 9:09:30 PM
dude wrote:

> Erwin Moller wrote:
>> dude wrote:
>> 
>> 
>>>i'll try to be short ... i have this in html :
>>>
>>><select name="OS[]" size="5">
>>>   <option value="0" selected>Please select one or more...</option>
>>>   <option value="1">Windows</option>
>>>   <option value="2">Mac OS X</option>
>>>   <option value="3">Linux</option>
>>></select>
>>>
>>>and i want to echo the values from this simple list (OS), i mean array
>>>from $_GET array ...
>>>
>>>i did this:
>>>
>>>foreach($_GET as $i => $val)
>>>     echo $i . ": " . $val . "<br>";
>>>
>>>but, it only echoes out OS: Array ...
>>>
>>>and this: echo $_GET['OS'][1]."<br>\n"; but it is wrong ...
>>>
>> 
>> 
>>>how to extract values from OS array inside te GET ? please help ...
>> 
>> 
>> Hi,
>> 
>> Your select is not an array, but a simple value, since only 1 can be
>> selected.
>> So if you want to know what was selected, just use:
>> <select name="OS" size="5">
>> 
>> and from PHP: $_GET["OS"]
>> 
>> Of course this means the method of the form was GET and not POST, in
>> which case you should use $_POST["OS"]
>> 
>> I think you are confusing checkboxes with select.
>> For checkboxes you can use:
>> <input type="checkbox" name="myval[]" value="1">1<br>
>> <input type="checkbox" name="myval[]" value="2">2<br>
>> <input type="checkbox" name="myval[]" value="3">3<br>
>> 
>> then from PHP:
>> $myvalArr = $_POST["myval"];
>> 
>> Regards,
>> Erwin Moller
> 
> thnx, but it is not about checkboxes ... this works fine with checkboxes
>   ... not with list :)

Yes it does.
DId you read my first piece of code?

<select name="OS" size="5">
and from PHP: $_GET["OS"]

What is excactly not working?

Regards,
Erwin Moller



0
6/19/2006 8:55:38 AM
Reply:
Similar Artilces:

array of file paths to array of strings
How do I change this array of the paths of all the files filearray = [1x105 char] [1x106 char] [1x106 char] [1x106 char] .. .. .. Into an array of strings? Do you know? I can't figure it out. Bruce Bassi wrote: > > > How do I change this array of the paths of all the files > > filearray = > > [1x105 char] > [1x106 char] > [1x106 char] > [1x106 char] > . > . > . > > Into an array of strings? > Do you know? I can't figure it out. Bruce, Take a look at cellstr. Scott When I put newstring = cellstr(filearray) it outputs the same ...

show array of array of array of array...
I'm trying to print an array of (datas and array of (datas and array of (datas and array..... Here is the code: ...

Re: call symput and arrays #5
lehmannk@med.uni-marburg.de wrote: >OK, so I trie to explain a little bit more of what I want to do. My rows >are the patients (n = 136). In the columns there are the 18 different >kinds of adverse events (for example Diarrhoe, sickness, ... and so >on). The adverse events can be graded from 0 to 4 and they can happen >at up to 11 diffrent timepoints (Registration and cycle 1 to 10). At the >moment I just want to have the maximum of every advers event about >all cycles for every patient. From this Maximum I want to subtract the >grade of the adverse event, which already...

vectorizing cell arrays; making cell arrays faster; for loops
I understand that typically "vectorizing" and removing for-loops makes Matlab code (within Matlab, I'm not talking about compiling/hand-converting to C, C++, etc.) faster inside the Matlab application. However, I have successfully "vectorized" some code involving "cell arrays" and it appears not to be significantly faster, it even may be somewhat slower. Is this to be anticipated? Is there a general paradigm for speeding up cell array operations? Is a double-for loop the best way to do this? Thanks, Sincerely, Joseph PhD and Matlab "exper...

picture arrays
I have been trying to add individual pictures to an array.&nbsp; I have an LED control array on the front panel, and I am converting it to a 1 pixel picture.&nbsp; I want to record several different shapes in an array--one at a time.&nbsp; How do I do this? &nbsp; Ronnie B Here is a better explanation of my problem: &nbsp; I am trying to build an array of pictures using LED controls on the front panel.&nbsp; For example, I need to store the alphabet A, B, C in a&nbsp;1x26&nbsp;array (each shape is made using a single 12x10 LED control array).&nbsp; I am ab...

Re: efficient array question #3
Adding IF havedata THEN before the second DO loop in each solution would eliminate the unnecessary check if the first do loop already found a terminating condition. -----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Muthia Kachirayan Sent: Thursday, December 10, 2009 12:29 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: efficient array question Jason, Here is another way. There is no need to pass macro variables. Your variables can be numeric and/or character. I give 2 array solutions, one is direct and the other is implict. data have; set ...

ALLOCATABLE array and LAPACK
I dynamically allocated a matrix using allocatable array ALLOCATE(MAT(N,N)) Can I subsequently use LAPACK subroutines to invert it,as if MAT(N,N) is an ordinary f77 array? best Bin "Bin Shan" <stanfordbshan@hotmail.com> writes: > I dynamically allocated a matrix using allocatable array > ALLOCATE(MAT(N,N)) > > Can I subsequently use LAPACK subroutines to invert it,as if MAT(N,N) is an > ordinary f77 array? As Mike Metcalf said in answer to your question on allocatable arrays 2 weeks ago, > Once an allocatable array is > allocated, it may be used i...

Scope of locally declared arrays
Consider the following function: void f(char *x) { *x = 1 ; } char g(void) { char a[16] ; char *p ; p = &a[0] ; f(p) ; return a[0] ; } My understanding is that g() should return 1 because the pointer passed to f() corresponds to a memory region that, although local to g(), is still in scope when g() gets invoked. Is this correct? On 2010-10-20, James H. Markowitz <noone@nowhere.net> wrote: > void f(char *x) > { > *x = 1 ; > } > char g(void) > { > char a[16] ; > char *p ; > > p = &a[0] ;...

copy char arrays
char cSubject[256]; chat *h_ptr[8]; If I want to copy the char array pointed by h_ptr[6] to cSubject character by character, does the code looke like the following: strcpy(cSubject+i,*(h_ptr[6])+i); chacha wrote: > char cSubject[256]; > chat *h_ptr[8]; > > If I want to copy the char array pointed by h_ptr[6] to cSubject > character by character, does the code looke like the following: > > strcpy(cSubject+i,*(h_ptr[6])+i); No, it is not valid. *(h_ptr[6]) would yield a value representing the first char in the char array to which h_ptr[6] is pointing. Function strc...

Re: array of array?
Hi guys, I have a problem... Suppose to have these easy lines: a=[1,2]; b=[5,8]; temp=[a,b]; I used disp(temp(1)) but it not show the first element of temp,that is what I want!!! How I can do? Thx.. Raffaele ...

splot using continuous array
Is there a way to create a surface plot using a continuous array of data in a file without breaking the data up into blocks? My data file has 76800 z values without any breaks. I want to display a 320 x 240 (xrange x yrange) splot. I was hoping to not manipulate the data before plotting it. Any easy way within gnuplot? Thanks In article <b48b2138-7983-45bd-9c8c-350139ef3e44@o6g2000hsd.googlegroups.com>, <eric_sorensen@cnsp.com> wrote: >Is there a way to create a surface plot using a continuous array of >data in a file without breaking the data up into blo...

array of array of float
i used C too much and haven't used Python for a while... like in C, if we want an array of array of float, we use float a[200][500]; now in Python, seems like we have to do something like a = [ [ ] ] * 200 and then just use a[1].append(12.34) etc but it turns out that all 200 elements points to the same list... and i have to use a = [ ] for i in range (0, 200): a.append([ ]) is there a simpler way... i wonder... Summercoolness@gmail.com wrote: > i used C too much and haven't used Python for a while... > > like in C, if we want an array of array of float, we ...

Return all fields from array of structs
I've been racking my brain over this but can't seem to find a vectorized way to accomplish this: Let's say I have struct x, which contains a linear array of elements r. y is a linear array of these structs. Note that the number of elements r for each object is different. If I type y.r at the command prompt, it displays all arrays of r from y(1:end). If I type test = y.r, I only get y(1).r. Why is this? How do I move y(1:end).r into a cell array without a for loop? Likewise, let's say another field in y is f. f is a single double value, not an array. How do I cop...

Green Arrays DevBoards!
http://www.greenarraychips.com/home/products/index.html Little pricey though... On Oct 20, 12:48 am, Mux <spam_catcher...@hotmail.com> wrote: > http://www.greenarraychips.com/home/products/index.html > > Little pricey though... The board as described appears rather minimal, but I don't consider $400 pricey. Eval boards are typically several hundred dollars. It is the very tiny, very limited EZ type kits that are under $50... well, given the minimal functionality of this eval board, maybe $400 is a bit high. It is interesting that it only has EIA-232 interfaces... no US...

Building an array of time, velocity and temp, but the first time recorded in the new array is always equal to the last time recorded in the last array (+1 or 2 seconds).
I'm creating a 3-by-y array (y depends on the duration of the test).&nbsp; The array consists of time, velocity and temperature.&nbsp; Generally, the interval is set to one second. The problem is that the first time element of the new array is always just a second or two later than the last time element of the last array, regardless of how much time has elapsed between tests (arrays).&nbsp; Any suggestions? The Final Gen 8 Furness vi is the one in question Write Characters To File+.vi: http://forums.ni.com/attachments/ni/170/175029/1/Write Characters To File+.vi Final Gen 8...

C++ Global Array Library
In the latest release of the Mumps Compiler code at http://www.cs.uni.edu/~okane are the libraries to access the Mumps global arrays from C++ programs. The necessary routines and examples are in the directory "mumpsc/m++". The Mumps Compiler must be installed in order for these routines to work. The following example shows several Mumps-like features and functions. The routines permit interpretation of Mumps code fragments and exchange of data between C++ and Mumps variables. /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #+ #+ Mumps Bioinformatics...

Re: Array question #27
Hi David, Of course, I know that. And of course it depends on the purpose whether denormalizing is applicable. And even if denormalizing might do a good job, a solution without denormalizing often is possible too, especially in the case of reporting or repeated measures analysis. Yet I developed the MR2RM denormalizing macro in the first instance for my own use when I chose to calculate differences and derive other variables by denormalizing. And doing so I wanted to denormalize (flatten, fold, hinge) many variables at once, based on the values of more than one (BY) variable, optionally assi...

How to create a second array that will cancel out the first array numerically tia sal22
Greetings All I have an array set with data points, which I then create a second array rotated 180 degrees using the rot90 command but when I combine the 2 data sets they don't cancel out what am I doing wrong? Should I be doing this a different way? I can't just multiply by zero I need to create the "anti-array" so it will cancel the first one out. Example code: clear data=[11.7850359299327 20; 11.7848969483503 10; 11.5577287219483 70; 11.5575059369603 35; 11.1848667706336 200; 11.1844912196924 100; 10.5086724317427 400; 10.5079357590755 200; 10.36046...

Count number of distinct value of an array
Dear SAS-L, I want to count the number of distinct value for several variables, I tried to use array, but how to do that? Suppose I have variables x1- x4 , I want to count distinct number of them. The desired data should be like following: x1 x2 x3 x4 num si ma ma fc 3 mn mn mn mn 1 si ma mn fc 4 Any suggestion will be appreciated! Jerry ...

Function to handle array with variable _number_ of dimensions?
I'd like to write a function that takes two integer arguments, P and Q say, and then returns a value calculated from the P x P x ... x P (Q factors) array, whose entries depend on both P and Q. My first impulse is to try and iterate over the array, but I don't see how to generate a non-fixed number of iteration variables. Does anyone have a suggestion of a good way to do this, short of writing a a distinct variant function for each possible value of Q? -- ============================= Joe Christy ============================== ------------------ http://public.xdi.org/=jo...

Arrays, Array scope, etc.
Given the code below I think I should get an alert message box that says "one" when the link is clicked - but instead i get an error that "x.1 is null or not an object" Thanks for any help - tom <script language="JavaScript"> var x = new array(); x[0] = "zero"; x[1] = "one"; function z() { alert(x[1]); } </script> <html> <body> <a href="javascript: z();">click here</a> </body> </html> "harborcoat-design" <tjhickey@gmail.com> wrote in message news:111159...

Operation with arrays
Dear Users, I construct the following arrays: %LET LO=3D1; %LET HI=3D98; DATA A; SET B; ARRAY VARIA {&LO:&HI}; RUN; DATA c; SET D; ARRAY CRED {&LO,&HI}; RUN; Now I want to subtract from each line varia1 ... varia98 another array=20 with size (1,98), that is, for each line of VARIA I need to subtract the=20 line Cred How can I do it? Thanks Rick Ricardo Gon=E7alves Silva, M. Sc. Tecnologia de Cr=E9dito=20 SERASA S.A.=20 =C9 (11) - 6847-8889 ? ricardosilva@serasa.com.br=20 ...

Vertex Arrays: Can OpenGL do what D3D can?
I would like to know if OpenGL can create MULTIPLE vertex buffers in video memory for static data. I keep reading about CVA's, VAR's etc. but it sounds like they all work like this: 1. Setup vertex/color/TC/normal arrays (glVertexPointer...) 2. Lock/set memory range 3. (Set matrices&DrawElements) * X 4. Unlock eventually Question 1: Is this correct in portraying how CVA's, VAR's, glLock... works? Question 2: If so, if we are using static and dynamic vertices, it sounds like it will be impossible to keep static arrays in VMem, because if we lock vertices for static data, ...

stable_sort with arrays?
Is it possible to do something like this: Team* League[4]; for (int team=0; team<4; team++) { League[team] = new Team; } std::stable_sort(League[0], League[3], TeamIsBetter ); *********************************** bool TeamIsBetter( Team* Team1, Team* Team2 ) { int PointsTeam1 = Team1->GetPoints(); int PointsTeam2 = Team2->GetPoints(); return PointsTeam2 > PointsTeam1; } Andreas Schmitt wrote: > Is it possible to do something like this: > > Team* League[4]; > > for (int team=0; team<4; team++) > > { > > League[team] = new Team; &g...

3-dimensionnal array
Hello, I am working with Fortran77 and Matlab, i am novice using Fortran. I have write a 3-dimensionnal file in fortran and would like to read it with matlab. In fact, I manage to read my 2-dimensionnal file using fread, but that's not possible to read a 3-dimensionnal array with fread. Have you got some ideas to read this file? Thank you, Anna "Aniouska Conchon" <pantouflettefuchia@gmail.com> wrote in message <huimj0$hg$1@fred.mathworks.com>... > Hello, > > I am working with Fortran77 and Matlab, i am novice using Fortran. > >...