Jump to content

Passing Arrays


sodascape

Recommended Posts

Like passing a kidney stone, i'm finding this difficult....

I have a page with a form and a bunch of different checkboxes, I want to put all of the selected checkbox values into an array.... which I have done, but then I want to take that array and pass it to another page....so on the second page, it shows all of the values in that array....  can't seem to get it.

Can you help?!?!
Link to comment
Share on other sites

Well this is off the top of my head, but I think its right;

Create the checkboxes like:
[code]
<form action="test.php" method="post">
<input type="checkbox" name="myarray[]" value="Value 1"><br />
<input type="checkbox" name="myarray[]" value="Value 2"><br />
<input type="checkbox" name="myarray[]" value="Value 3"><br />
<input type="checkbox" name="myarray[]" value="Value 4"><br />
<input type="submit" value="test">
</form>[/code]

Then for debugging purposes:
test.php
[code]<?php
print_r($_POST["myarray"]);
?>[/code]

hth :)
Link to comment
Share on other sites

A form on one page, with a bunch of CHECKBOX items, all of the selected CHECKBOX items are added to an array via the form......and then the ARRAY is sent to another page and on that page, the items of the array are displayed.

EXAMPLE:  Page 1 has "select colors"  I pick out RED, GREEN and BLUE.... then I click the SUBMIT button and it takes me to the next page, and on Page 2 it says "You have selected the colors: RED GREEN AND BLUE.  Make sense?
Link to comment
Share on other sites

Well!

You can't pass an array directly from one page to another page(this i came to know by this forum :( when i had the same problem!)

If you are passing the values from one form to another..via POST ..there you can pass it.

If in case you want to pass an array from one page to another page using URL ..before passing it you should make it as a string .like this

[code]
<?php
$str=implode(",",$array);
?>
[/code]

in next page you have to use explode function to form it as an array again!

Third case if you want to pass it using a SESSION variable..simply assign it to a session variable.

[code]
<?php
$_SESSION['name']=array()# you can assign it directly too..but in case if array had  a single value in it..the this session will act as a string.

$_SESSION['name']=$array;
?>
[/code]

Regards
Joshi.
Link to comment
Share on other sites

[quote author=sodascape link=topic=114615.msg466418#msg466418 date=1163235217]
A form on one page, with a bunch of CHECKBOX items, all of the selected CHECKBOX items are added to an array via the form......and then the ARRAY is sent to another page and on that page, the items of the array are displayed.

EXAMPLE:  Page 1 has "select colors"  I pick out RED, GREEN and BLUE.... then I click the SUBMIT button and it takes me to the next page, and on Page 2 it says "You have selected the colors: RED GREEN AND BLUE.  Make sense?
[/quote]

That's basically what heckenschutze's code does
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.