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'],1 2,13);
$south = substr($_SESSION['Data'],1 4,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
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'].
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
$work = $strt."%";
$north = substr($_SESSION['Data'],1
$south = substr($_SESSION['Data'],1
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
Is there any reason you can't simply make $_SESSION['Data'] an array?
$_SESSION['Data'] = array(
'north' => '...',
'south' => '...',
'other' => '...',
'stuff' => '...
);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I stared at the code and could not see it.
We've all done that! Welcome to the club :-)
Open in new window
http://us3.php.net/manual/en/function.substr.php