array in $_GET ...

  • Permalink
  • submit to reddit
  • Email
  • Follow


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
Reply dude.j (9) 6/16/2006 11:47:03 AM

See related articles to this posting

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
Reply since_humans_read_this_I_am_spammed_too_much (2445) 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
Reply 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
Reply 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
Reply 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
Reply david.haynes2 (308) 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
Reply 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
Reply 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
Reply since_humans_read_this_I_am_spammed_too_much (2445) 6/19/2006 8:55:38 AM
comp.lang.php 32477 articles. 6 followers. Post

8 Replies
57 Views

Similar Articles

[PageSpeed] 46

  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

array $_GET
Hi, why: $n = count($_GET); for($i=0; $i<$n; $i++) { echo $_GET[$i] } Doesn't work? sen Sen schrieb: > Hi, > > why: > > $n = count($_GET); > for($i=0; $i<$n; $i++) > { > echo $_GET[$i] > } > > Doesn't work? > sen If you open index.php?test=hallo, then you can access the value with $_GET['test']. Your loop now tries to echo $_GET[0] for example, but you need to echo $_GET['test'] in order to see anything. :-) If you want to walk through an array, use foreach ($array as $value) { echo $value; } On Tue...

Values not passed to $_GET array
I have a form with a lot of text boxes. The values are showing up in the address bar of the browser, but the $_GET array does not show any values. It does have the correct names of input boxes. There are option boxes on this form also, and those values work. Not sure whats going on. Fabiof wrote: > I have a form with a lot of text boxes. The values are showing up in > the address bar of the browser, but the $_GET array does not show any > values. It does have the correct names of input boxes. There are > option boxes on this form also, and those values work. Not sure whats > go...

PHP5 and Global Array ($_GET)
I had a client recently contact me with a script that wasn't working. I quickly isolated the problem as to the fact that the $_GET array was not being made available to all scripts, even though register_globals was set to ON. The client then notified his host who seemed to know exactly the issue and we added these lines to the top of the script (this script is included in all other scripts) and it solved the problems: /* mp.net patch */ foreach($_GET as $var => $value) $$var = $value; foreach($_POST as $var => $value) $$var = $value; foreach($_COOKIE as $var => $value) $$var = ...

varaible passed through URL is not in $_GET array
Hi, I am passing a variable through url. www.example.com/maxmoney.php?id=xyz@yahoo.com In the maxmoney.php I have tried to catch it this way $email=$_GET['id']; when i echoed $email or $_GET['id']; its not displaying. I am using php 5. I could not figure out what the issue is. can any help me? Thanks in advance, sharma sharma wrote: > I am passing a variable through url. > www.example.com/maxmoney.php?id=xyz@yahoo.com Lose the @ with http://php.net/urlencode -- E. Dronkert sharma wrote: > Hi, > > I am passing a variable through url. > www.example.c...

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: show array of array of array of array...
sorry..the code: function printtree($array, $level){ while(list($k,$v) = each($array)) if(is_array($k)){ print("$k -><br>"); printtree($k,$level++); } else { for($i=0;$i<$level;$i++) print("&nbsp;"); print("$k : $v<br>"); } } but it does only print the first level and get out !!! I can't figure what's wrong.... Please help !!!! BoB Bob Bedford wrote: > sorry..the code: > > function printtree($array, $level){ > while(list($k,$v) = each($array)) > if(is_array($k)){ > print(&quo...

const and array of array (of array ...)
Imagine I have an array of arrays of ints and want to sum all the ints. #include <stdio.h> int sumints(int arr[3][3]) { int c, r, s=0; for (r=0; r<3; r++) { for (c=0; c<3; c++) { s += arr[r][c]; } } return s; } int main(void) { int my_array[3][3] = {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}}; printf("sum of ints is %d\n", sumints(my_array)); return 0; } I tried to define the su...

Arrays Of Arrays: Is it an Array or Scalar?
I have a function that I'm using to perform operations on strings in an array. There are times where I'd like to have this function work on arrays of arrays. Is there a simple way to tell if the value of an element in an array is a scalar, or is, instead, a reference to another array? I know I can use a regex to see if the string matches the pattern for an array reference, but is there a more "elegant" and easier way to do it? (And, while I'm at it, is there a way to check for a hash as well? I'd think they'd both be done the same way.) Thanks! Hal In <...

Length of Array of Array of Array
How to find the length of an "Array of Array of Array" I get syntax error when i say $#fx[0][0][0] X-Ftn-To: Tom sudhirx@gmail.com (Tom) wrote: >How to find the length of an "Array of Array of Array" > >I get syntax error when i say $#fx[0][0][0] This should give you the latest index from third level array, $#{ $fx[0][0] } -- Matija Tom <sudhirx@gmail.com> wrote: > How to find the length of an "Array of Array of Array" > > I get syntax error when i say $#fx[0][0][0] Well first off, the $#array syntax does NOT give you the leng...

An array of arrays
My problem is I need to create a loop which will store 40 images in separate arrays. Here is my code: for n=[1:1:40] if n<10 A1='subFolder\photo000'; elseif n>9 A1='subFolder\photo00'; end A2=num2str(n); A3='.jpg'; fileDir=strcat(A1,A2,A3); rgb_img = imread(fileDir); end The problem is I want a range of arrays like: rgb_img1 rgb_img2 rgb_img3 .... rgb_img40 Do I need to use a 3 dimensional array for this. I am genuinely confused. :) Cheers, Chris "Chris " <chris.taeni@gmail.com> wrote in message news:i5ms2l$652$1@fre...

convert array to array-of-arrays?
Rubies: Given [1, 2, 3, 4], what's the most Rubiesque way to get [[1, 2], [3, 4]]? I had figured a variation on Array#transpose would be available, but I can't find one! -- Phlip On Feb 4, 10:45 am, Phlip <phlip2...@gmail.com> wrote: > Rubies: > > Given [1, 2, 3, 4], what's the most Rubiesque way to get [[1, 2], [3, 4]]? > > I had figured a variation on Array#transpose would be available, but I can't > find one! > > -- > Phlip have a look at enum.partition (http://ruby-doc.org/core/classes/ Enumerable.html#M003161) cheers Chris Hu...

How to separate array from array of arrays
Hello I don't know if what I wrote in subject makes any sense. I have an array in which there are two entries, which are again arrays (one is numbers and one is text). Like I have entry called NEWDATA1 in workspace and in NEWDATA1 , there are entries called 'data' and 'textdata'. I want to separate 'data' (which is a column of numbers) from NEWDATA1. I actually imported a file (concfromcmg1.txt) which looks like Global Mole Fraction(SOL) 2000-01-01 1,1,1’ *SRF-FORMAT 0 Global Mole Fraction(SOL) 2000-01-03 1,1,1’ *SRF-FORMAT 0.705627 ...

Multidimensional arrays and arrays of arrays
Hello How can I distinguish if an array is multidimensional of if it just contains an array? Or put it another way how can I tell at runtime whether a/b in the example below is an array containing an array, or if it is a multidimensional array. If I know beforehand exactly which type it is, I can use instanceof (see example), but I don't (especially the number of dimensions, I don't know). Else I can call getClass().getName() on the object and see if it starts with "[[" (pretty ugly IMHO). Is there another, cleaner method to do this? public static void main(String[] args) { ...

array of array
Hi, I need to create something like a matrix, say 32 bits on each row and up to 4 rows. That's why on my Spartan3 I have to receive 32 bits word from a serial port and I have to store them (I know I can just place a 32x4 bits long vector and store the data in the same row, but I'd like to learn more about array of array). I wrote: type row is array (cmd_buffer_word downto 0) of std_logic; type cmd_buffer is array (cmd_buffer_depth downto 0) of row; now, how could I transfer the whole 32 bits data inside a vector called cmd_tmp_buffer into the second row of my cmd_buffer? This follow...

array of array
I've to save in an array of array some values. Problem: I don't know the size of the array before filling it. I'd like something like $bigarray = array(): then runnig the code I must create dinamically (I don't know how many) few arrays in the bigarray; $bigarray["X"] = array(): $bigarray["Y"] = array(): then fill those arrays with few unknow number of values. array_push($bigarray["X"],$value1); array_push($bigarray["X"],$value2); array_push($bigarray["Y"],$value5); .... but array_push doesn't manage it. How to do so...

array of...array....
I've this structure in a XML file: Type Model Detail Datas Datas Datas Datas /Detail Detail Datas Datas Datas /Detail /Model /Type I've parsed all the stuff, by putting everything in an array. Now, I've a problem as I must use datas in "Detail" tag every time they are processed, but I must first process datas in Model, so I have to wait until Model tag is closed. For now I put everything in an array called $datas (where I store the couple key/valu...

array or not array?
Hi all, i'm a real noob in databasedesign, so i have some questions about it. In case i want to make a booklist with two tables and the following fields: owner_table has the fields ID, name, books book_table has the fields ID, author, title, isbn normally i would say, this is easy, just filling both tables with data and linking them together maybe like owner_table.books as a foreign key linked to book_table.isbn or book_table.ID. In this way i will have many datasets in owner_table with the same entry in 'name', depending on how much books this man (or women) has. ...

When is an array not an array?
Hi, folks. I've encountered what seems to me to be something of an oddity while playing around with XML parsing in PHP, and I wondered if any of you might be able to clear up my confusion... Here's a little code: $xmlDoc = new DOMDocument(); $xmlDoc->load('widget_data.xml'); $widgets = $xmlDoc->getElementsByTagName('widget'); My understanding was that '$widgets' is an array of elements, and the following 'foreach' iterates through that array (this works): foreach ($widgets as $widget) { .... } However, I get an error if I try to access ...

Array in Array
Hi guys, I have a question dealing with arrays. Here it go: Suppose A is a 3 by 1 array, I want to assign A (1,1) a 5 by 1 array B, can I do this? How? Thanks in advance! "George " <guanjihou@gmail.com> wrote in message <hutpgd$km$1@fred.mathworks.com>... > Hi guys, > > I have a question dealing with arrays. Here it go: > > Suppose A is a 3 by 1 array, I want to assign A (1,1) a 5 by 1 array B, can I do this? How? > > Thanks in advance! Hi George, make A a cell array A = cell(3,1); B = randn(5,1); A{1} = B; Wayne % Us...

Array of arrays
Hello, How do I define an array of arrays ? Suppose T is an array of 3 elements. And I want T[0] = intarr(2,5,4), T[1] = intarr(6,5,4) and T[2] = intarr(7,8,4). How do I declare T ? Francois. Fritz writes: > How do I define an array of arrays ? > > Suppose T is an array of 3 elements. > And I want T[0] = intarr(2,5,4), T[1] = intarr(6,5,4) and T[2] = > intarr(7,8,4). > > How do I declare T ? As a pointer array. :-) t = PtrArr(3) t[0] = Ptr_New(intarr(2,5,4)) t[1] = Ptr_New(intarr(6,5,4)) t[3] = Ptr_New(intarr(7,8,4)) (*t[1])[0,*,2] = Indgen(...

Array of Array
Hello, I am wondering if a three-dimensional arrays: array3d_1, array3d_2, array3d_3. Is it wise If pass this to a function/subroutine using array constructor to create four-dimensional array on the fly, such as: call mysubroutine ( (/array3d_1, array3d_2, array3d_3/) ) ? Will that be expensive, or is there better way to do it ? I am also not certain if this on-the-fly array construction will be the first or the last dimension. Thanks for any help. RDB reubendb <reubendb@gmail.com> wrote: > I am wondering if a three-dimensional arrays: > array3d_1, array3d_2, array3d_3. > Is...

array of array?
Hi, there, I wonder, if that is possible to have a array of arrays, for example A(1)=a1(1:N,1:M); A(2)=a2(1:N,1:M); A(3)=a3(1:N,1:M); � If no such thing, is there any simple method to do the same things as dimension A(i,j,k) in Fortran? Could any one please input anything? Thanks hnliuhy wrote: > > > Hi, there, > I wonder, if that is possible to have a array of arrays, for > example > A(1)=a1(1:N,1:M); > A(2)=a2(1:N,1:M); > A(3)=a3(1:N,1:M); > � > > If no such thing, is there any simple method to do the same things > as > dimension > A(i,j,k) in Fo...

Array of array
Hi friends, Please kindly assist me with an answer to this question: Is it possible to create a Matlab array whose elements are in turn 3 element arrays? I mean, how can I create an array as A = {(1,2,2), (3,2,1), (5,3,4), etc}. If possible, how do I access the elements of this array. If not, could this be possible in Fortran? Thanks. On 12/25/2012 8:14 PM, CHINEDU wrote: > Hi friends, > Please kindly assist me with an answer to this question: > > Is it possible to create a Matlab array whose elements are in turn 3 element arrays? > I mean, how can I create an arr...

arrays in arrays?
In PERL I can put arrays in arrays. my @array1 = ('val1', 'val2', 'val3'); my @array2 = ( \@array1 ); In TCL I'm trying set arr1(key1) val1 set arr1(key2) val2 set arr1(key3) val3 set arr2(key4) $arr1 Tclsh rightfully complains that $arr1 is a scalar and not an array. How do I set an array as the value in another array? Mike Mike schrieb: > In PERL I can put arrays in arrays. > > my @array1 = ('val1', 'val2', 'val3'); > my @array2 = ( \@array1 ); > > In TCL I'm trying > > set arr1(key1) val1 > set arr1(...