Jump to content

[SOLVED] passing arrays through sessions?


flusho

Recommended Posts

Yes, you can send arrays through sessions. I created a shopping list for my wife and when she checks the items she wants to print, it creates an array and sets to a session. On the print page I take the session and break up the session into 3 arrays to make 3 colums on the page.

 

 

Here is where I grab the $_POST data, and set it as a session

 

<?php
$list_items= $_POST['list_items'];


if ($_POST['printit']){
session_start();  //start the session
$_SESSION['list_items']= $list_items; // set the session to the $_POST var above
echo'<meta http-equiv="refresh" content="0;URL='.$root.'shopping_list/printing.php" target="_blank" >';

};
?>

 

Here is where I take the entire list and break it up into 3 columns containing 45 items each

 

<?php
session_start();

$list=array_slice($_SESSION['list_items'],0,45);
$list2=array_slice($_SESSION['list_items'],46,45);
$list3=array_slice($_SESSION['list_items'],91,45);

// more code below here......
?>

 

 

Just remember to start_session() before you try to set the session vars.

 

Also you are creating a multi-dimensional array here as $_SESSION is an array as well

 

Nate

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.