473,549 Members | 2,588 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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">Windo ws</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 ...
Jun 16 '06 #1
8 11894
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">Windo ws</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
Jun 16 '06 #2
"dude" <du****@gmail.c om> wrote in message
news:e6******** **@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">Windo ws</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="multi ple">

--
"ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk
sp**@outolempi. net | Gedoon-S @ IRCnet | rot13(xv***@bhg byrzcv.arg)
Jun 16 '06 #3
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">Windo ws</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($_G ET 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 :)
Jun 16 '06 #4
> 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="multi ple">


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 :)


Jun 16 '06 #5
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="multi ple">


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("Selecte d %s<br>\n", $value);
}
}
?>
<html>
<head></head>
<body>
<form action="test.ph p" method="GET">
<select name="OS[]" size="5" multiple>
<option>Windows </option>
<option>Linux </option>
</select>
<input type="submit">
</form>
</body>
</html>

-david-
Jun 16 '06 #6
ED

"dude" <du****@gmail.c om> wrote in message
news:e6******** **@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="multi ple">


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 overcomplicatin g 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="multi ple">
<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">L inux</option>
</select>

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

cheers,
ED
Jun 16 '06 #7
Thank you all ! I'm grateful. This works perfect!

Looks like I was overcomplicatin g things :)
Jun 16 '06 #8
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">Windo ws</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($_GE T 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

Jun 19 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
19113
by: gf | last post by:
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...
3
7432
by: Duyet The Vo | last post by:
Hi, script_a.php .... $data = array ( ..., ... ); <a href="script_b.php?data=$data">script b</a> .... ========== script_b.php
6
10972
by: brian_mckracken | last post by:
This might not be the right group for this question, since its kind of a pure html question... Given the html construct: <form action='index.php?expand=0,10000' method='post'> Email: <input type='text' name='login' size='30'/> Password:<input type='password' name='login' size='30'/> </form>
5
5371
by: Chuck Anderson | last post by:
I have finally started coding with register_globals off (crowd roars - yeay!). This has created a situation that I am not sure how I should handle. I have scripts (pages) that can receive an input variable from the POST array (initial entry) or it could be in the GET array (go back and re-edit a form, for instance.) In my old sloppy...
10
1818
by: alanbe | last post by:
I am working on some scripts to help me automate the website creation process. I want to use a template for the whole website and call pages using something like 'http://localhost/template.php?page=links' I actually have a working system, but I thought I would improve by using comma-separated key => value pairs.
8
1903
by: Michael Wild | last post by:
Hi all I'm not quite new to PHP, but also not very proficient in its use, so please excuse me if my question is a FAQ. Perhaps I didn't know the right terms, but google wasn't my friend this time :-) I had a page running on a host which worked perfectly fine. Then, one day, it stopped working since strangly some values in the $GLOBALS...
4
10719
by: Sen | last post by:
Hi, why: $n = count($_GET); for($i=0; $i<$n; $i++) { echo $_GET }
8
9637
by: seni786 | last post by:
Hi i am having problems with some code that i wrote out for a shopping cart. the shopping cart it self works when a product is added but when the 'CART CONTENT' button is clicked on it comes up with an error. the error is Notice: Undefined index: action in D:\www\students\khank\WebsiteFinal1SHAZAD\cart.php on line 5 the code that i have...
1
1043
by: Freelancer Deepak | last post by:
hi friends i have a problem i have written a code for accepting table name , feld names and datatype from user and i want to create a table in database . my problem is that i am auable to create a string for creating table can you suggest me the solutions. I this code $tname is table name , fname is array containg values field names and Dtype...
0
7527
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7459
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7726
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7967
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7485
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7819
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5377
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3505
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1064
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.