2

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

5
  • Can you add some code to your question? You may have to look into serialization but I am not entirely sure. Commented Feb 25, 2016 at 20:59
  • What does the session variable with the array look like ? Commented Feb 25, 2016 at 21:00
  • I am storing the result of a query in a session variable in one page and in another page, I want to use this session variable to print database values like the values in particluar coumns Commented Feb 26, 2016 at 5:02
  • Side note: you may want to add a die; after header("location:dists.php"); line or the code, considering you have some of it after that block, will still get executed before the redirect. Commented Feb 26, 2016 at 5:42
  • No, there's no code after the header, just that 'if' loop ends. Commented Feb 26, 2016 at 5:48

1 Answer 1

1

Using foreach():

foreach($_SESSION['array'] as $row) {
   echo $row;
}
Sign up to request clarification or add additional context in comments.

1 Comment

@Vyshnavi Samudrala ... and move the $_SESSION[ 'arrrows' ] = $arr_row; line to after the while() block.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.