user5923290
user5923290

Reputation:

How to fetch data from a session variable having an array

I have a session variable storing an array in it. Now, in another PHP page, I want to print these array values row by row... Just like the result from mysqli_fetch_array function does

$sql="SELECT complaints.c_id , user.first_name , user.last_name  FROM ogc.complaints , ogc.user WHERE complaints.department='$deptname' and complaints.id=user.id and complaints.district='$distr' " or die(mysql_error());
$result=mysqli_query($conn,$sql) ;
$count=mysqli_num_rows($result);
if(count>0)
{
    $row = array();
    $arr_row[]=array();
    while( $row = mysqli_fetch_array( $result ) )   
    {   
        $arr_row[]=$row;
        $_SESSION[ 'arrrows' ] = $arr_row;
        header("location:dists.php");
    }
}

In the dists.php

    session_start();
    $result=$_SESSION['arrrows'];

Now, I want to use this $result to access individual rows and columns of the array by the column names of different rows

Upvotes: 2

Views: 1768

Answers (1)

Thomas Orlita
Thomas Orlita

Reputation: 1627

Using foreach():

foreach($_SESSION['array'] as $row) {
   echo $row;
}

Upvotes: 1

Related Questions