...

View Full Version : array



bunny1
03-09-2007, 09:13 PM
I'm trying to pass an array from one page to another and display it's contents on the next page.

This is the code I am using



$var1 = $_GET["name"];

foreach($var1 as $value)

echo $value;

I keep getting this error "Warning: Invalid argument supplied for foreach() in..\..\..\..\..."

Any ideas?

shyam
03-09-2007, 09:25 PM
$var1 = $_GET["name"];

are u sure $var1 is an array?

bunny1
03-09-2007, 09:48 PM
i passed an array in the form action of a form using this line

"deleted.php?name=$array"

where $array is an array in the page it is sent from

is it possible to send an array this way
and is there a way of checking if it is an array on the pg it is sent to?

foreach is not working for me

thanks

aedrin
03-09-2007, 09:58 PM
Doing this:



$array = array(1, 4, 3, 4);
$url = "index.php?array=".$array;
echo $url;


Will not work. You cannot pass an array that way.

You should consider using sessions, or perhaps try this depending on what is in the array:

Page 1:


$array = array(1, 4, 3, 4);
$url = "index.php?array=".urlencode(implode(', ', $array));
echo $url;


index.php


$array = explode(',', urldecode($_GET['array']));

shyam
03-09-2007, 10:03 PM
http requests are sent as text not as php objects...


"deleted.php?name=" . implode(',', $array)

and when u get it back


$var1 = $_GET["name"];
$arr = explode(',', $array);

foreach should now work on $arr



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum