Pass arrays from page a to b

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
aetoc
Forum Commoner
Posts: 37
Joined: Tue Jan 31, 2006 2:48 am

Pass arrays from page a to b

Post by aetoc »

I wander if I can pass arrays from page a to page b with the a tag (without the use of forms).

Thanks.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

Use serialize() and unserialize().
You may need to use urlencode() and urldecode().
Last edited by Oren on Tue Jun 06, 2006 3:55 am, edited 1 time in total.
aetoc
Forum Commoner
Posts: 37
Joined: Tue Jan 31, 2006 2:48 am

Post by aetoc »

Thanks.
aetoc
Forum Commoner
Posts: 37
Joined: Tue Jan 31, 2006 2:48 am

Post by aetoc »

The serialize in page a gives me this ...
a:2:{i:0;s:22:"ATT00005_692716197.jpg";i:1;s:28:"ATT00005_692716197_thumb.jpg";}

But in page b I get only this...
a:2:{i:0;s:22:

Do you know y and what can I do?
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

Post your code.
aetoc
Forum Commoner
Posts: 37
Joined: Tue Jan 31, 2006 2:48 am

Post by aetoc »

twigletmac | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


page a:

Code: Select all

while (($file2 = readdir($open_folder)) !== false)
 {
  if ($file2 != "." AND $file2 != ".." AND $file2 != "Thumbs.db")
   {
    if ($_POST['change'.$file_id] == "on")
     {
      $to_used[$file_to] = $file2;
      $file_to++;
     }
    $file_id++;
   }
  }
closedir($open_folder);

$to_used = serialize($to_used);
<a href="<?php echo $url."&fileto=".$file_to."&to_used=".$to_used; ?>" target="index">Bip Bip !!!</a>
page b:

Code: Select all

$file_id = 0;
$to_used = unserialize($to_used);
while ($file_id < $fileto)
  {
  echo $to_used[$file_id];
  $file_id++;
  }
Thanks for everything


twigletmac | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Code: Select all

<a href="?foo[]=42&foo[]=10&foo[]=12">Click me</a>

<?php

if (isset($_GET['foo']))
{
    print_r($_GET['foo']; //array( 42, 10, 12 )
}

?>
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

There is no point to post the whole code. Next time post only the relevant code.
This is enough:

Code: Select all

$to_used = serialize($to_used);
<a href="<?php echo $url."&fileto=".$file_to."&to_used=".$to_used; ?>" target="index">Bip Bip !!!</a>

Code: Select all

$file_id = 0;
$to_used = unserialize($to_used);
Now change it to this and tell us what happens:

Code: Select all

$to_used = urlencode(serialize($to_used));
<a href="<?php echo $url."&fileto=".$file_to."&to_used=".$to_used; ?>" target="index">Bip Bip !!!</a>

Code: Select all

$file_id = 0;
$to_used = urldecode(unserialize($to_used));
Post Reply