Page 1 of 1

send an array through post and get method

Posted: Mon Sep 22, 2003 2:57 am
by yaron
Hello,
Is it possible to send an array through post or get?
page1:

$arr=array('hello','goodbye');
echo "<a href=page2.php?a=$arr>tp page 2</a>";

page2:
if(isset($a))
print_r($a);

and the same for post...

Thanks..

Posted: Mon Sep 22, 2003 3:04 am
by Nay
Nope, I tested it, I get Array echoed out. If you want, you might want to do like:

Page 1:

Code: Select all

<?
$arr=array('hello','goodbye');
$arr=implode(",",$arr);
echo "<a href=pg2.php?a=$arr>tp page 2</a>"; 
?>
Page 2:

Code: Select all

<?
if(isset($a)) {
$a = explode(",", $a);
echo $a[0];
}
?>
-Nay

Posted: Mon Sep 22, 2003 3:20 am
by yaron
will this work if i make a more complex array (with elements that are arrays too)?

Posted: Mon Sep 22, 2003 3:25 am
by Nay
I don't think so, It'll get all jumbled up.

-Nay

Posted: Mon Sep 22, 2003 3:48 am
by yaron
can't I use [] like we do on checkbox selection for example?

Posted: Mon Sep 22, 2003 3:50 am
by Nay
I'm not sure. I'm not very familiar with arrays. I use MySQL for all my data needs.

-Nay

i c

Posted: Mon Sep 22, 2003 4:01 am
by yaron
ok, I'll try it
thx anyway
p.s
nice pic :-)

Posted: Mon Sep 22, 2003 4:02 am
by Nay
haha, thanks. Which one btw? :-D. The pic that appears are random.

-Nay

Posted: Mon Sep 22, 2003 4:14 am
by yaron
hmmm... yes you are right...
well, they are all nice...haha

Posted: Mon Sep 22, 2003 4:26 am
by JayBird
errrr.....why not use sessions?

Then your arrays, no matter how complex will be available to your scripts.

Unless you REALLY need to use post or get, but without stating your reason for wanting to achieve this, i can't say much more.

Mark

Posted: Mon Sep 22, 2003 4:34 am
by yaron
I thought about that but i have a problem.
I create a table full of links each needs to send different values i.e. my array.
the easiest is using <a href> with get method. I can't create so many sessions it will slow my server.
I thought about using the post method to send my array as a string and explode it later. is it possible to create so many forms? an I submit them without specify a form name?

Posted: Mon Sep 22, 2003 4:39 am
by JayBird
why not just send one unique value on the <a href> then on the next page, generate your array depending on that value.

Mark

Posted: Mon Sep 22, 2003 4:53 am
by volka
I can't create so many sessions it will slow my server.
are you sure loading the session-data when needed is slower than shifting the data forth and back the inet connection over and over again?

implode() can handle multidimensional arrays.

Posted: Mon Sep 22, 2003 4:54 am
by yaron
I can't do that...
I have to much data to send.
I think the post thing will work I jave just 1 problem with that..
because I have many forms and I gave them unique names e.g. f1,f2,f3....
I try to send to the java script function in order to submit a form but when I can't seem to be able to eval my form name in the js func
any ideas?