Link to home
Start Free TrialLog in
Avatar of breeze351
breeze351

asked on

Passing data in $_Session vars

I have a page (BuildingChk.php) that is used by several other pages.  Depending on the page that it came from, it passes data in $_SESSION['Data'].  

The page I'm having trouble with needs to add 2 variables to session variable.  I'm building the session variable like so:

$_SESSION['Data'] = $ROW2['SEQ'].$ROW2['NOR'].$ROW2['SOU'];

This does work.  

My problem is the length of "NOR" and "SOU".  They could be any where from 1 to 4 chars.

Is there a way to set them to 4 chars before building the string?

Also, the following code comes from the page that get's the results.

I've modified the code so that it is only looking for 2 chars in north and south (quick fix).

echo $_SESSION['Data']."<br>";
$strt = substr($_SESSION['Data'],0,9);
$work = $strt."%";
$north = substr($_SESSION['Data'],12,13);
$south = substr($_SESSION['Data'],14,15);
echo $strt."<br>";
echo $work."<br>";
echo $north."<br>";
echo $south."<br>";

The results that I'm getting from the "echo" statements are as follows:
NY10350005755251
NY1035000
NY1035000%
5251
51

Everything is correct except for the $north.  Why is it returning 4 chars instead of 2?

Thanks
Glenn
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Because the second number is supposed to be the length, not the ending position.
$north = substr($_SESSION['Data'],12,2);
$south = substr($_SESSION['Data'],14,2);

Open in new window

http://us3.php.net/manual/en/function.substr.php
Avatar of zappafan2k2
zappafan2k2

Is there any reason you can't simply make $_SESSION['Data'] an array?
$_SESSION['Data'] = array(
    'north' => '...',
    'south' => '...',
    'other' => '...',
    'stuff' => '...
);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of breeze351

ASKER

I stared at the code and could not see it.
We've all done that!  Welcome to the club :-)