Page 1 of 1

Newbie - PHP/HTML POST SESSION Array help needed.

Posted: Thu May 04, 2006 8:17 am
by pmehta
feyd | 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]


Can somebody please help? I am trying to get an Array passed using session variable. As the following code shows, the results of an sql query are displayed from an array. This part works fine. Now I want to store what the user selects from this list in a session array and pass it on to the next page
All I get in the session array is the word Array. Please help.

Code: Select all

<?php
session_start();
echo "<select multiple=multiple name=assessment_value[] size=5>";

$assesslist=array();
$assesslist=get_assessment_list_by_org($conn,$org_ index);
$i=0;
while ($i!=count($assesslist))
{
printf("<option value=\"%s\">%s\t%s",$assesslist[$i][0],$assesslist[$i][2],$assesslist[$i][1]);
$i++;
}
echo"</select>";

if(count($_POST['assessment_value'] > 0)){
$assess_index_gen = implode(",",$_POST['assessment_value']);
}
else {
echo "nothing in assessment value";
}
$_SESSION['gbl_assess_index'] = $assess_index_gen;
?>

feyd | 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: Thu May 04, 2006 8:25 am
by Charles256
if it's just echoing array you need to access an individual element of the array. i.e. $array[0] will give you the first element. :)

Posted: Thu May 04, 2006 8:25 am
by cj5
Did you start the session anywhere before this code?

Posted: Thu May 04, 2006 8:42 am
by pmehta
The session has been started and infact I am using couple session variables from previous pages for some other tasks as well. The issue here is that I want to pass ONLY the "selected" items to the next page as a session variable or a session array.

Posted: Thu May 04, 2006 9:34 am
by feyd
If you want to pass it as an internal array, why attempt to implode it?

The count() call just before the implode() is a likely fault. (You need to move a closing paren to the left a few places.)

Posted: Thu May 04, 2006 9:52 am
by pmehta
I don't want to use implode() if I don't have to. I was just try to make it simpler by passing a delimited string instead of an array.
Could I use

$_SESSION['gbl_ass_index'] = $_POST['assessment_value'];

instead? I am not sure if the assessment_value has any data in it. Should I be passing the array assess_list instead?