Current location: Hot Scripts Forums » Programming Languages » PHP » Passing Session Arrays


Passing Session Arrays

Reply
  #1 (permalink)  
Old 01-07-06, 06:08 AM
DAL's Avatar
DAL DAL is offline
Code Master
 
Join Date: Jun 2003
Location: North East England/UK
Posts: 874
Thanks: 0
Thanked 0 Times in 0 Posts
Red face Passing Session Arrays

Hi everyone

I am having problems keeping values of arrays. I want a form that when a user types a value and hits submit button that value is read into an array then displayed on the page. Every time the user types a value, all values show.

in my submit test I have

$title[$roomcount] = $_POST['title'];
$roomcount++;

each time the user hits submit the $roomcount variable increases. The first element ref in the array is 0, then 1 ..etc

I have tried all sorts to keep the values stored in $title but it only remembers the last input entered. I know I would have to probably use $_SESSION['title'] and read the array back into $title but have problems.
I have tried
$_SESSION['title'] = serialize($title);
then
$title = unserialize($_SESSION['title']);

but that doesnt remember more than 1 entry the rest are empty.

I could try a foreach statment loop but I dont know the syntax for accessing arrays with $_SESSION['title']

is it $_SESSION['title[0]']
this seams to act as though title[0] is actually the name for the variable rather then have the array ref at the end.

I have also tried $_SESSION['title'][0] and $_SESSION[$title[]] but I think I just got the server laughing at me

Thanks
__________________
"once upon a midnight dreary, while i pron surfed, weak and weary, over many a strange and spurious site of 'hot xxx galore'. While i clicked my fav'rite bookmark, suddenly there came a warning, and my heart was filled with mourning, mourning for my dear amour," 'Tis not possible!", i muttered, "give me back my free hardcore!" quoth the server, 404."
Reply With Quote
  #2 (permalink)  
Old 01-07-06, 04:13 PM
DAL's Avatar
DAL DAL is offline
Code Master
 
Join Date: Jun 2003
Location: North East England/UK
Posts: 874
Thanks: 0
Thanked 0 Times in 0 Posts
I think I confused everyone. I guess it shows how confused I am.

heres it put simply;

how can you write $title which is an array into a $_SESSION array. Then how do you access the individual elements of that array. ie if you can write $title[0] & $title[14] to access the first and fourteenth element how do you access them in the $_SESSION array?
__________________
"once upon a midnight dreary, while i pron surfed, weak and weary, over many a strange and spurious site of 'hot xxx galore'. While i clicked my fav'rite bookmark, suddenly there came a warning, and my heart was filled with mourning, mourning for my dear amour," 'Tis not possible!", i muttered, "give me back my free hardcore!" quoth the server, 404."
Reply With Quote
  #3 (permalink)  
Old 01-07-06, 05:23 PM
acosonic acosonic is offline
New Member
 
Join Date: Jan 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Solution

Hi I got my own session functions. I had the same problem so I made it. It works flawlessly.

I can give it to You.
Reply With Quote
  #4 (permalink)  
Old 01-07-06, 05:47 PM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by DAL
I think I confused everyone. I guess it shows how confused I am.

heres it put simply;

how can you write $title which is an array into a $_SESSION array. Then how do you access the individual elements of that array. ie if you can write $title[0] & $title[14] to access the first and fourteenth element how do you access them in the $_SESSION array?
The following does work (verified just now) -
PHP Code:

<?php

session_start
();
// The array arr_a contains some values to store in the session variable
$arr_a = array("somevalue_a""somevalue_b""somevalue_c");

// Store arr_a into session variable savearr
$_SESSION['savearr'] = $arr_a;

// Get the session variable savearr into an array
$arr_b $_SESSION['savearr'];

// Make use of the array elements...
echo "$arr_b[0]<br>";
echo 
"$arr_b[1]<br>";
echo 
"$arr_b[2]<br>";
?>

Last edited by mab; 01-07-06 at 05:57 PM.
Reply With Quote
  #5 (permalink)  
Old 01-07-06, 05:56 PM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
Here is an update - This syntax works -

PHP Code:

$_SESSION['savearr'][0];

$_SESSION['savearr'][1];
$_SESSION['savearr'][2]; 

Last edited by mab; 01-07-06 at 05:59 PM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
urgent: session timeout occurs unexpectedly in ASP.net seemagaur ASP.NET 3 10-11-05 11:10 PM
Session validation sharad JavaScript 1 08-15-05 05:47 PM
SESSION Arrays Jaffizzle PHP 2 05-30-05 02:38 PM
session help darkcarnival PHP 5 05-09-05 12:40 AM
how do I manage session cookies? Jansen Windows .NET Programming 1 05-04-05 03:32 PM


All times are GMT -5. The time now is 06:27 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.