how to pass array from one page to another php page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wenquxing
Forum Newbie
Posts: 9
Joined: Thu Dec 02, 2004 12:17 am

how to pass array from one page to another php page

Post by wenquxing »

how to pass array from one page to another php page
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post 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.
wenquxing
Forum Newbie
Posts: 9
Joined: Thu Dec 02, 2004 12:17 am

Post 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?
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post 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.
wenquxing
Forum Newbie
Posts: 9
Joined: Thu Dec 02, 2004 12:17 am

Post 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?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

use url - en/de - code functions.
Post Reply