Page 1 of 1

Pass arrays from page a to b

Posted: Tue Jun 06, 2006 3:35 am
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.

Posted: Tue Jun 06, 2006 3:52 am
by Oren
Use serialize() and unserialize().
You may need to use urlencode() and urldecode().

Posted: Tue Jun 06, 2006 3:53 am
by aetoc
Thanks.

Posted: Tue Jun 06, 2006 4:33 am
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?

Posted: Tue Jun 06, 2006 4:40 am
by Oren
Post your code.

Posted: Tue Jun 06, 2006 4:46 am
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]

Posted: Tue Jun 06, 2006 5:07 am
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 )
}

?>

Posted: Tue Jun 06, 2006 5:22 am
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));