Hi,
(Newbie to php). I am trying to read in a list of ids. Here is my
url http://localhost/a.php?id=1&id=2&id=3
Then I just want to print out the ids, but I can't seem to get it
work. I search php.net and have tried a dozen things I can't get to
work
Tried:
print "<BR> 0=" . $_REQUEST['id'][0];
print "<BR> 1=" . $_REQUEST['id'][1];
But it only prints the last id.
Tried:
foreach ($_REQUEST['id'] as $value) {
print "<BR> $value";
}
Can someone help simple question?
thanks
chad 7 2055
In article <1e************ **************@ posting.google. com>, ch**@windmeadow .com (chad phillips) wrote: Hi,
(Newbie to php). I am trying to read in a list of ids. Here is my url
http://localhost/a.php?id=1&id=2&id=3
What you want is: http://localhost/a.php?id[]=1&id[]=2&id[]=3
Your code should work simply by changing the URL. It's not pretty, but
AFAIK it's the only way to pass an array through the query-string.
hth
--
Bulworth : fu***@fung.arg | My email address is ROT13 encoded, decode to mail
--------------------------|--------------------------------------------------
<http://www.phplabs.com/> | PHP scripts and thousands of webmaster resources!
Senator Jay Billington Bulworth a écrit le 15/03/2004 : What you want is:
http://localhost/a.php?id[]=1&id[]=2&id[]=3
Your code should work simply by changing the URL. It's not pretty, but AFAIK it's the only way to pass an array through the query-string.
hth
I suggest using serialize() and unserialize() to pass arrays in URL.
Beware of the protection of slashes, you may need to use stripslashes()
as well.
chad phillips wrote: Hi,
(Newbie to php). I am trying to read in a list of ids. Here is my url
http://localhost/a.php?id=1&id=2&id=3
Then I just want to print out the ids, but I can't seem to get it work.
Why don't you pack up the ids in a delimited array if they're simple
numbers: http://localhost/a.php?id=1,2,3
Then:
$ids = explode(',',$_G ET['id']);
foreach ($ids as $id) {
...
}
That would work. In perl I can read in http://localhost/a.php?id=1&id=2&id=3. I figured there must be a way
to do the same thing in php. As someone pointed out I can change them
to http://localhost/a.php?id[]=1&id[]=2&id[]=3, but it seems weird
that php could handle id=1&id=2&id=3
thanks
chad
Kevin Thorpe <ke***@pricetra k.com> wrote in message news:<40******* *************** @news.easynet.c o.uk>... chad phillips wrote: Hi,
(Newbie to php). I am trying to read in a list of ids. Here is my url
http://localhost/a.php?id=1&id=2&id=3
Then I just want to print out the ids, but I can't seem to get it work.
Why don't you pack up the ids in a delimited array if they're simple numbers:
http://localhost/a.php?id=1,2,3
Then: $ids = explode(',',$_G ET['id']);
foreach ($ids as $id) { ... }
On Mon, 15 Mar 2004 03:28:16 GMT, Senator Jay Billington Bulworth
<fu***@fung.arg > wrote: In article <1e************ **************@ posting.google. com>, ch**@windmeadow .com (chad phillips) wrote:
(Newbie to php). I am trying to read in a list of ids. Here is my url
http://localhost/a.php?id=1&id=2&id=3
What you want is:
http://localhost/a.php?id[]=1&id[]=2&id[]=3
Your code should work simply by changing the URL. It's not pretty, but AFAIK it's the only way to pass an array through the query-string.
IMHO this is the one thing that ASP does right over PHP (I suppose it has to
do _something_ right). Send multiple values and you get an array; you don't
need to put [] in the name, causing arguments about whether it's valid HTML (it
is).
If you have multiple elements with the same name at the moment, I'm not
entirely sure it's deterministic which value you'll end up with in PHP, and
non-determinism is generally annoying in a programming language. If it's
deterministic, I don't think it's documented, which is nearly as bad.
I think PHP ought to at least have a config option to accept multiple values
not ending in [] as arrays - although I suppose since PHP is open-source I
ought to just get on with it and write a patch if it bothers me ;-)
--
Andy Hassall <an**@andyh.co. uk> / Space: disk usage analysis tool
<http://www.andyh.co.uk > / <http://www.andyhsoftwa re.co.uk/space>
Uzytkownik "Andy Hassall" <an**@andyh.co. uk> napisal w wiadomosci
news:do******** *************** *********@4ax.c om... IMHO this is the one thing that ASP does right over PHP (I suppose it has
to do _something_ right). Send multiple values and you get an array; you
don't need to put [] in the name, causing arguments about whether it's valid
HTML (it is).
That would cause massive number of type-mismatch errors, since PHP doesn't
automatically convert a scalar to an array with one item based on the
context.
If you have multiple elements with the same name at the moment, I'm not entirely sure it's deterministic which value you'll end up with in PHP,
and non-determinism is generally annoying in a programming language. If it's deterministic, I don't think it's documented, which is nearly as bad.
There's documentation, kind of. The comment for variables_order in php.ini
reads "[r]egistration is done from left to right, newer values override
older values." In the OP, $_GET['id'] would yield 3.
On Mon, 15 Mar 2004 19:16:34 -0500, "Chung Leong" <ch***********@ hotmail.com>
wrote: Uzytkownik "Andy Hassall" <an**@andyh.co. uk> napisal w wiadomosci news:do******* *************** **********@4ax. com... IMHO this is the one thing that ASP does right over PHP (I suppose it has to do _something_ right). Send multiple values and you get an array; you don't need to put [] in the name, causing arguments about whether it's valid HTML (it is).
That would cause massive number of type-mismatch errors, since PHP doesn't automaticall y convert a scalar to an array with one item based on the context.
Well, yes, there is that. Fair point.
But people have nearly got over register_global s, we need a new configuration
option to break things again ("Why do all my database rows have 'Array' in
them?!") ;-)
(Slightly related: I'm not that keen on arrays stringifying to Array either -
ought to raise a warning, I don't see how 'Array' is useful). If you have multiple elements with the same name at the moment, I'm not entirely sure it's deterministic which value you'll end up with in PHP, and non-determinism is generally annoying in a programming language. If it's deterministic, I don't think it's documented, which is nearly as bad.
There's documentation, kind of. The comment for variables_order in php.ini reads "[r]egistration is done from left to right, newer values override older values." In the OP, $_GET['id'] would yield 3.
Variables_order is for the order that globals and $_REQUEST source their
information from; if it's GP then reading from left to right, GET variables are
overwritten by POST variables. But it doesn't say what happens for the multiple
GET variables of the same name.
3 seems the logical choice but I can't find the documentation that actually
says that.
The HTML spec at least guarantees the order they're sent out - same 'order
they appear in the document stream' (HTML4.01 sec 17.3.4).
--
Andy Hassall <an**@andyh.co. uk> / Space: disk usage analysis tool
<http://www.andyh.co.uk > / <http://www.andyhsoftwa re.co.uk/space> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Geoff Cox |
last post by:
Hello,
I am trying to print out the array values for a second time but get
error on page message?
Thanks
Geoff
<html>
|
by: Alan |
last post by:
hi all,
I want to define a constant length string, say 4
then in a function at some time, I want to set the string to a constant
value, say a
below is my code but it fails
what is the correct code?
many thx!
|
by: Ross A. Finlayson |
last post by:
I'm trying to write some C code, but I want to use C++'s std::vector.
Indeed, if the code is compiled as C++, I want the container to
actually be std::vector, in this case of a collection of value types or
std::vector<int>.
So where I would use an int* and reallocate it from time to time in C,
and randomly access it via , then I figure to copy the capacity and
reserve methods, because I just need a growable array.
I get to considering...
|
by: purna chandra |
last post by:
Hello,
I have a simple question.Hoping not to take much of
your valuable time...:-). I am trying to get the data
from a string, and am wondering if I get
http://groups.google.com/intl/en/googlegroups/tour/index.html
from the array :
array('c',
'\x00=http://groups.google.com/intl/en/googlegroups/tour/index.html'))
Thanks in advance,
|
by: number1.email |
last post by:
Hello, I have a simple Web Page Questionairre in which questions are
read from a database, and the user can indicate the correct answer via
either a radio input control or a dropdown list. The number of
questions that is displayed on the screen can vary...depending on the
number of questions that satisfy certain criteria. Does anyone have
any sample code, or can show me how I can validate this Web Page in
JavaScript so that the user is...
| |
by: karan.shashi |
last post by:
Hey all,
I was asked this question in an interview recently:
Suppose you have the method signature
bool MyPairSum(int array, int sum)
the array has all unique values (no repeats), your task is to find two
|
by: Armand |
last post by:
Hi Guys,
I have a set of array that I would like to clear and empty out.
Since I am using "Array" not "ArrayList", I have been struggling in
finding the solution which is a simple prob for those who experience.
(For some reason I have to implement Array not ArrayLists)
Below are the simple following code:
Dim Array() As String
Dim intCounter As Integer
|
by: AndersWang |
last post by:
Hi,
dose anybody here explain to me why memset would be faster than a
simple loop. I doubt about it!
In an int array scenario:
int array;
for(int i=0;i<10;i++) //ten loops
|
by: sam |
last post by:
hI,
I am little confused here
See
i have
int wordlen=10;
when int s is array
s++;
whats the meaning of this
|
by: Ronald Raygun |
last post by:
I want to be able to randomly select the following from an array:
1). An image
2). A piece of text (name of tge image)
3). A piece of text (description of the image)
I want to be able to build a static array with the values hardcoded into
the array, and then be able to randomly select an item from the array
and retrieve the image, name and description.
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |