Page 1 of 1

how to pass array from one page to another php page

Posted: Thu Dec 02, 2004 11:04 am
by wenquxing
how to pass array from one page to another php page

Posted: Thu Dec 02, 2004 11:26 am
by protokol
You can use [php_man]session[/php_man]s, you can post the data using a form, you can [php_man]serialize[/php_man] the array and put it into the query string. Take your pick.

Posted: Thu Dec 02, 2004 11:57 am
by wenquxing
I tried to serilize the array$info:
$temp=serialize($info);

but how to put the $temp in the url
I was using:<a href="detail.php?var=$temp"> but the value in $_get [var]is "$temp",not the content in the array.
anyone can help?

Posted: Thu Dec 02, 2004 12:06 pm
by protokol
When setting the url you do this:

Code: Select all

<?php
$temp = serialize( $info );
?>
<a href="detail.php?var=<?php echo $temp ?>">
When you retrieve the array (which you serialized), then when you access it you do this:

Code: Select all

<?php
$array = unserialize( $_GET['var'] );
?>
This will convert the value back into an array, which it started as to begin with. Then you just treat $array as you would a normal array.

Posted: Thu Dec 02, 2004 12:48 pm
by wenquxing
thanks a lot, protokol

I did what you wrote above, but I still get a problem, the array after I serialize is

"a:3:{i:0;a:6{i:0;i:1;s:2:" ID";i:1;i:1;s:30:"news1 ";s:5:"title";s:30:"news1 ";i:2;s:200:"content1 ";s:7:"content";s:200:"content1 ";}i:1;a:6:{i:0;i:2;s:2:"ID"; ".......

but what I got in the $_GET is :

" a:3:{i:0;a:6:{i:0;i:1;s:2:"

I think the " mark before ID make it PHP stop scanning the whole string, is there any solution to solve this?

Posted: Thu Dec 02, 2004 1:23 pm
by timvw
use url - en/de - code functions.