[FX.php List] Beating a dead horse (was: trying to read back an
array)
Joel Shapiro
jsfmp at earthlink.net
Mon Sep 20 10:19:16 MDT 2010
Hi Bob
You might have figured this out already, but here are some thoughts of
mine:
What's the session array supposed to be capturing? Is it individual
items that need service, with data specific to each of those items
(serial, type, description, etc)?
Are users sending more than one item per POST? What does the
$_POST['recid'] array look like? And if recid's are in an array, why
doesn't the other data come in with them in the same array (it looks
like they come in as $_POST['description12'],
$_POST['description213'], etc.)
I think the goal would be to end up with a $_SESSION array like this,
containing an [item] array ($_SESSION['item']):
Array
(
[item] => Array
(
[12] => Array
(
[description] => pen
[type] => ballpoint
[problem] => doesn't click
[serial] => 42X5W
)
[213] => Array
(
[description] => pen
[type] => quill
[problem] => leaks
[serial] => 35LL53W8
)
[569] => Array
(
[description] => iPod
[type] => Nano
[problem] => too loud
[serial] => UR3298
)
)
)
For setting this up, I'd do the following for each item that comes in
via POST:
$_SESSION['item'][$recid] = array(
'description' => $_POST['description'.$recid],
'type' => $_POST['type'.$recid],
'problem' => $_POST['problem'.$recid],
'serial' => $_POST['serial'.$recid]
);
HTH,
-Joel
On Sep 17, 2010, at 9:12 AM, Bob Patin wrote:
> OK, I can do that, but at this point nothing's been written to the
> DB, so i don't have a support_request value per se; I suppose I can
> generate one.
>
> Question: should it not work this way since every user only has one
> array of recid?
>
> How do I retrieve the session key? I know there's a command for it,
> just being lazy...
>
> BP
>
>
> On Sep 17, 2010, at 11:06 AM, Dale Bengston wrote:
>
>> Oh, okay. I think then you should set your session main key to the
>> id of their support request, and then make sub-arrays for every
>> item in the support request.
>>
>> $suppReq = [wherever you store that value];
>>
>>
>> if( (strlen($_POST['recid'])>0) && (is_array($_POST['recid']))) {
>> foreach($_POST['recid'] as $recid) {
>> $_SESSION[$suppReq][$recid]['description] = $_POST['description'.
>> $recid] ;
>> $_SESSION[$suppReq][$recid]['type'] = $_POST['type'.$recid] ;
>> $_SESSION[$suppReq][$recid]['serial'] = $_POST['serial'.$recid] ;
>> $_SESSION[$suppReq][$recid]['problem'] = $_POST['problem'.$recid] ;
>> $_SESSION[$suppReq][$recid]['recid'] = $recid ;
>> }
>> }
>>
>> foreach($_SESSION[$suppReq] as $recid => $value) {
>> $status = "Open; pending manufacturer approval";
>> $description = $value['description'];
>> $problem = $value['problem'];
>> $serial = $value['serial'];
>> echo $recid;
>>
>>
>>
>>
>>
>> On Sep 17, 2010, at 10:45 AM, Bob Patin wrote:
>>
>>> I don't think that'll work; here's the thing:
>>>
>>> the user may visit this page multiple times, similar to a cart;
>>> they may come here, having added a support request, then leave,
>>> find another item that needs service, and add it too.
>>>
>>> So that's why i need to build this array; each time they get to
>>> this page, i want to show them the list of items that they've
>>> selected so far for repair.
>>>
>>> So that means that my 2nd loop has to loop thru the array and not
>>> my POST values...
>>>
>>> Make sense? So that being the case, why isn't it pulling in my
>>> array?
>>>
>>> BP
>>>
>>>
>>> On Sep 17, 2010, at 10:32 AM, Dale Bengston wrote:
>>>
>>>> This (and subsequent lines) should be:
>>>>
>>>> $_SESSION[$recid]['description'] = $_POST['description'.$recid] ;
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> On Sep 17, 2010, at 9:59 AM, Bob Patin wrote:
>>>>
>>>>> Well, I'm almost there, but here's what is happening:
>>>>>
>>>>> When I read back the array using this:
>>>>>
>>>>> foreach($_SESSION['recid'] as $recid => $value) {
>>>>> $status = "Open; pending manufacturer approval";
>>>>> $description = $value['description'];
>>>>> $problem = $value['problem'];
>>>>> $serial = $value['serial'];
>>>>>
>>>>> I get back 4 records, and my data isn't there (getting a single
>>>>> letter in each value)...
>>>>>
>>>>> Here's how I'm writing my vars:
>>>>>
>>>>> if( isset($_POST['recid']) && is_array($_POST['recid'])) {
>>>>> foreach($_POST['recid'] as $recid) {
>>>>> $_SESSION['recid']['description'] = $_POST['description'.
>>>>> $recid] ;
>>>>> $_SESSION['recid']['type'] = $_POST['type'.$recid] ;
>>>>> $_SESSION['recid']['serial'] = $_POST['serial'.$recid] ;
>>>>> $_SESSION['recid']['problem'] = $_POST['problem'.$recid] ;
>>>>> }
>>>>> }
>>>>>
>>>>> I should get back only ONE record, so the array should be empty
>>>>> other than that one; I closed my browser just to make sure I'd
>>>>> ended the previous session...
>>>>>
>>>>> Do I need to filter out empty data? Why am I not getting my vars
>>>>> back?
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> FX.php_List mailing list
>>>>> FX.php_List at mail.iviking.org
>>>>> http://www.iviking.org/mailman/listinfo/fx.php_list
>>>>
>>>> _______________________________________________
>>>> FX.php_List mailing list
>>>> FX.php_List at mail.iviking.org
>>>> http://www.iviking.org/mailman/listinfo/fx.php_list
>>>
>>> _______________________________________________
>>> FX.php_List mailing list
>>> FX.php_List at mail.iviking.org
>>> http://www.iviking.org/mailman/listinfo/fx.php_list
>>
>> _______________________________________________
>> FX.php_List mailing list
>> FX.php_List at mail.iviking.org
>> http://www.iviking.org/mailman/listinfo/fx.php_list
>
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list
More information about the FX.php_List
mailing list