Re: Pass an array using GET or POST?
| From: | Yurais Fernandez Leal | Date: | Sat, 24 Jun 2000 14:40:01 +0000 |
| Subject: | Re: Pass an array using GET or POST? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-2906@lists.php.net to get a copy of this message | ||
SUre it helps :-) at least for me, don't know for the owner of the
post ...
On Thu, 22 Jun 2000, Jeff Gannaway wrote:
webmas: At 05:36 PM 6/22/00 -0600, Scott S. Nicholson wrote:
webmas: >Is there any way to pass an array from one page to another using GET or
webmas: >POST?
webmas:
webmas: There may be an easy way around this, but here's what I've done in the past:
webmas:
webmas: <?
webmas:
webmas: // Note that the array can be defined any way and can be of any size.
webmas: // The lines below are only for this example.
webmas: $MyArray[0] = "Apples";
webmas: $MyArray[1] = "Oranges";
webmas: $MyArray[2] = "Grapes";
webmas: $MyArray[3] = "Peaches & Pears";
webmas:
webmas: // Now find out the size of the array.
webmas: $Size = sizeof($MyArray);
webmas:
webmas: // Now run through a WHILE loop to go through each array item.
webmas: $Counter = 0;
webmas: WHILE ($Counter < $Size)
webmas: {
webmas: // IT IS VERY IMPORTANT TO RAWURLENCODE() EACH ARRAY ITEM. If you don't, a
webmas: // value such as "Peaches & Pears" will louse up the URL.
webmas:
webmas: $MyArrayEncoded[$Counter] = RAWURLENCODE($MyArray[$Counter]);
webmas:
webmas: // This loop will print HIDDEN INPUT tags for the use of form. You can also
webmas: // combine them togeter in a string to make an <A HREF= > tag. Whatever.
webmas:
webmas: PRINT "<INPUT TYPE=HIDDEN NAME=MyArray[$Counter]
webmas: VALUE=\"$MyArrayEncoded[$Counter]\">";
webmas:
webmas: $Counter++;
webmas: }
webmas:
webmas: ?>
webmas:
webmas: The rsulting form will look something like:
webmas:
webmas: <INPUT TYPE=HIDDEN NAME=MyArray[0] VALUE="Apples">
webmas: <INPUT TYPE=HIDDEN NAME=MyArray[1] VALUE="Oranges">
webmas: <INPUT TYPE=HIDDEN NAME=MyArray[2] VALUE="Grapes">
webmas: <INPUT TYPE=HIDDEN NAME=MyArray[3] VALUE="Peaches%20%26%20Pears">
webmas:
webmas: When it goes to another PHP script, it will create an array named $MyArray
webmas: and populate the first 4 values with the ones you sent.
webmas:
webmas: Hope this helps,
webmas: -Jeff Gannaway
webmas:
webmas:
--
----------------------------------
Yurais Fernández Leal
MediRed Network SysAdmin.
yurais@medired.scu.sld.cu
http://www.scu.sld.cu/
ICQ: 33792610 ICQ-GW: 1031
Phone: (53) 226-54204
------------