need help using multi-dimensional arrays

This is a discussion on need help using multi-dimensional arrays within the PHP Language forums, part of the PHP Programming Forums category; Hi every one I'm try to use multi-dimensional arrays and store the data in Sessions and every time ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-12-2008
sahm
 
Posts: n/a
Default need help using multi-dimensional arrays

Hi every one
I'm try to use multi-dimensional arrays and store the data in Sessions
and every time I add new data to the same array
but I have problem ever time I try to add now data it's renew all
array
Please help me

this is my code
///////////////////////////////
<?php
session_start();
require_once('user_session.php');

$fristName = $_GET["fName"];
$fatherName = $_GET["faName"];
$famliyName = $_GET["fmName"];

$userData = array();
$userData["frName"] = $fristName;
$userData["faName"] = $fatherName;
$userData["fmName"] = $famliyName;

$allData = array();
$allData[]= $userData;
session_register('allData');

$dataShow = null;

if($fristName != null)
{
if($fatherName != null)
{
if($famliyName != null)
{
$dataShow = <<<HERE
<table border='1' cellpadding='1' cellspacing='1'>
<tr>
<th>
NO
</th>
<th>
Frist Name
</th>
<th>
Fahter Name
</th>
<th>
Famliy Name
</th>
</tr>
<tr>
HERE;
foreach($_SESSION['allData'] as $ad)
{
$dataShow .="<strong>".$ad['frName']."</strong>";
$dataShow .="<strong>".$ad['faName']."</strong>";
$dataShow .="<strong>".$ad['fmName']."</strong>";
}
$dataShow .="<td>";
$dataShow .= "&nbsp;";
$dataShow .="</td>";
$dataShow .="<td>";
$dataShow .=$userData["frName"];
$dataShow .="</td>";
$dataShow .="<td>";
$dataShow .=$userData["faName"];
$dataShow .="</td>";
$dataShow .="<td>";
$dataShow .=$userData["fmName"];
$dataShow .="</td>";
$dataShow .="</tr>";
$dataShow .="</table>";

echo $dataShow;

}
}
}
?>

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
best
Salim
Reply With Quote
  #2 (permalink)  
Old 02-12-2008
Rik Wasmus
 
Posts: n/a
Default Re: need help using multi-dimensional arrays

On Tue, 12 Feb 2008 15:36:01 +0100, sahm <sahm007@gmail.com> wrote:

> Hi every one
> I'm try to use multi-dimensional arrays and store the data in Sessions
> and every time I add new data to the same array
> but I have problem ever time I try to add now data it's renew all
> array
> Please help me
>
> this is my code
> ///////////////////////////////
> <?php
> session_start();
> require_once('user_session.php');
>
> $fristName = $_GET["fName"];


I suppose you mean $firstName, not $firstName? Allthough, you are
consequent in this..

> $fatherName = $_GET["faName"];
> $famliyName = $_GET["fmName"];
>
> $userData = array();
> $userData["frName"] = $fristName;
> $userData["faName"] = $fatherName;
> $userData["fmName"] = $famliyName;


Snip this:

> $allData = array();
> $allData[]= $userData;
> session_register('allData');


Do this:

$_SESSION['allData'] = isset($_SESSION['allData']) ? $_SESSION['allData']:
array();
$_SESSION['allData'][] = $userdata;

(And forget about the session_register() function, it's kind of deprecated
as you don't want register globals on, and we have a convenient $_SESSION
array).

> $dataShow = null;
>
> if($fristName != null)
> {
> if($fatherName != null)
> {
> if($famliyName != null)
> {


if(!empty($firstname) && !empty($fatherName) && !empty($familyName)){
--
Rik Wasmus
Reply With Quote
  #3 (permalink)  
Old 02-12-2008
sahm
 
Posts: n/a
Default Re: need help using multi-dimensional arrays

On Feb 12, 6:14 pm, "Rik Wasmus" <luiheidsgoe...@hotmail.com> wrote:
> On Tue, 12 Feb 2008 15:36:01 +0100, sahm <sahm...@gmail.com> wrote:
> > Hi every one
> > I'm try to use multi-dimensional arrays and store the data in Sessions
> > and every time I add new data to the same array
> > but I have problem ever time I try to add now data it's renew all
> > array
> > Please help me

>
> > this is my code
> > ///////////////////////////////
> > <?php
> > session_start();
> > require_once('user_session.php');

>
> > $fristName = $_GET["fName"];

>
> I suppose you mean $firstName, not $firstName? Allthough, you are
> consequent in this..
>
> > $fatherName = $_GET["faName"];
> > $famliyName = $_GET["fmName"];

>
> > $userData = array();
> > $userData["frName"] = $fristName;
> > $userData["faName"] = $fatherName;
> > $userData["fmName"] = $famliyName;

>
> Snip this:
>
> > $allData = array();
> > $allData[]= $userData;
> > session_register('allData');

>
> Do this:
>
> $_SESSION['allData'] = isset($_SESSION['allData']) ? $_SESSION['allData']:
> array();
> $_SESSION['allData'][] = $userdata;
>
> (And forget about the session_register() function, it's kind of deprecated
> as you don't want register globals on, and we have a convenient $_SESSION
> array).
>
> > $dataShow = null;

>
> > if($fristName != null)
> > {
> > if($fatherName != null)
> > {
> > if($famliyName != null)
> > {

>
> if(!empty($firstname) && !empty($fatherName) && !empty($familyName)){
> --
> Rik Wasmus



Dear Rik Wasmus
Thank you vary much for your help
it's help me a lot
Best
Salim
Reply With Quote
  #4 (permalink)  
Old 02-16-2008
sahm
 
Posts: n/a
Default Re: need help using multi-dimensional arrays

On Feb 12, 7:36 pm, sahm <sahm...@gmail.com> wrote:
> On Feb 12, 6:14 pm, "Rik Wasmus" <luiheidsgoe...@hotmail.com> wrote:
>
>
>
> > On Tue, 12 Feb 2008 15:36:01 +0100, sahm <sahm...@gmail.com> wrote:
> > > Hi every one
> > > I'm try to use multi-dimensional arrays and store the data in Sessions
> > > and every time I add new data to the same array
> > > but I have problem ever time I try to add now data it's renew all
> > > array
> > > Please help me

>
> > > this is my code
> > > ///////////////////////////////
> > > <?php
> > > session_start();
> > > require_once('user_session.php');

>
> > > $fristName = $_GET["fName"];

>
> > I suppose you mean $firstName, not $firstName? Allthough, you are
> > consequent in this..

>
> > > $fatherName = $_GET["faName"];
> > > $famliyName = $_GET["fmName"];

>
> > > $userData = array();
> > > $userData["frName"] = $fristName;
> > > $userData["faName"] = $fatherName;
> > > $userData["fmName"] = $famliyName;

>
> > Snip this:

>
> > > $allData = array();
> > > $allData[]= $userData;
> > > session_register('allData');

>
> > Do this:

>
> > $_SESSION['allData'] = isset($_SESSION['allData']) ? $_SESSION['allData']:
> > array();
> > $_SESSION['allData'][] = $userdata;

>
> > (And forget about the session_register() function, it's kind of deprecated
> > as you don't want register globals on, and we have a convenient $_SESSION
> > array).

>
> > > $dataShow = null;

>
> > > if($fristName != null)
> > > {
> > > if($fatherName != null)
> > > {
> > > if($famliyName != null)
> > > {

>
> > if(!empty($firstname) && !empty($fatherName) && !empty($familyName)){
> > --
> > Rik Wasmus

>
> Dear Rik Wasmus
> Thank you vary much for your help
> it's help me a lot
> Best
> Salim



Dear Mr. Rik Wasmus
Thank for your help
I have one more problem
How can I make ($_SESSION['allData']) available for all my php file or
function in another file

and I will be Thank full for your help

Best Salim
Reply With Quote
  #5 (permalink)  
Old 02-16-2008
Rik Wasmus
 
Posts: n/a
Default Re: need help using multi-dimensional arrays

On Sat, 16 Feb 2008 16:17:09 +0100, sahm <sahm007@gmail.com> wrote:

> On Feb 12, 7:36 pm, sahm <sahm...@gmail.com> wrote:
>> On Feb 12, 6:14 pm, "Rik Wasmus" <luiheidsgoe...@hotmail.com> wrote:
>>
>>
>>
>> > On Tue, 12 Feb 2008 15:36:01 +0100, sahm <sahm...@gmail.com> wrote:
>> > > Hi every one
>> > > I'm try to use multi-dimensional arrays and store the data in

>> Sessions
>> > > and every time I add new data to the same array
>> > > but I have problem ever time I try to add now data it's renew all
>> > > array
>> > > Please help me

>>
>> > > this is my code
>> > > ///////////////////////////////
>> > > <?php
>> > > session_start();
>> > > require_once('user_session.php');

>>
>> > > $fristName = $_GET["fName"];

>>
>> > I suppose you mean $firstName, not $firstName? Allthough, you are
>> > consequent in this..

>>
>> > > $fatherName = $_GET["faName"];
>> > > $famliyName = $_GET["fmName"];

>>
>> > > $userData = array();
>> > > $userData["frName"] = $fristName;
>> > > $userData["faName"] = $fatherName;
>> > > $userData["fmName"] = $famliyName;

>>
>> > Snip this:

>>
>> > > $allData = array();
>> > > $allData[]= $userData;
>> > > session_register('allData');

>>
>> > Do this:

>>
>> > $_SESSION['allData'] = isset($_SESSION['allData']) ?

>> $_SESSION['allData']:
>> > array();
>> > $_SESSION['allData'][] = $userdata;

>>
>> > (And forget about the session_register() function, it's kind of

>> deprecated
>> > as you don't want register globals on, and we have a convenient

>> $_SESSION
>> > array).

>>
>> > > $dataShow = null;

>>
>> > > if($fristName != null)
>> > > {
>> > > if($fatherName != null)
>> > > {
>> > > if($famliyName != null)
>> > > {

>>
>> > if(!empty($firstname) && !empty($fatherName) && !empty($familyName)){


> How can I make ($_SESSION['allData']) available for all my php file or
> function in another file


$_SESSION is a superglobal, so it will be available anywhere in the
script, provided you have called session_start(). This should be done on
every request you want to use the $_SESSION array in.


--
Rik Wasmus
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:54 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0