Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-22-2011, 03:19 PM   PM User | #1
JustBob
New Coder

 
Join Date: Sep 2011
Posts: 16
Thanks: 4
Thanked 0 Times in 0 Posts
JustBob is an unknown quantity at this point
Variable not updating always getting a NULL VALUE

PHP Code:
if(isset($_POST['add'])){
foreach(
$_SESSION as $ps => $value){
$getcartname = (explode('_'$ps));
if(
$getcartname[0] == 'ps'){
$getLine = (explode('_'$ps));
$line $getLine[0];
$getVal = (explode('_'$value));
$arrayContent $getVal[0];
$arrTotal += $arrayContent;
}
}
if(
$line == ''){
$line 1;
}
else{
$line++;
}
$_SESSION['ps_'.$line] = $num.'_'.$totalqtyt.'_'.$amount;
tempList();

The script is suppose to do...

If add has been set, check the array with ps_ if $line is NULL meaning the array is empty, set the $line to 1 if not increment $line.

My problem is it doesnt seem to increment line after the first 'clicking' of $_POST['add']; What seems to be the problem?

Last edited by JustBob; 10-22-2011 at 04:03 PM..
JustBob is offline   Reply With Quote
Old 10-22-2011, 04:28 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
This can be simplified:
PHP Code:
$iTotal 0;
$line 0;
foreach (
$_SESSION AS $ps => $value)
{
    list(
$type$line) = explode('_'$ps);
    if (
strcascmp($type'ps') == 0)
    {
        list(
$num$qty$amt) = explode('_'$value);
        
$iTotal += $num;
    }
}
$line $line ? ++$line 1
This of course does not accommodate for gaps. IMO this is also way too much work, sessions are serialized, and any type that can be serialized can be added to a session. This does include arrays and objects, so you can add as many dimensions as you want and can completely avoid the explode mess.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Tags
array, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:15 AM.


Advertisement
Log in to turn off these ads.