如何从具有数组的会话变量中获取数据

时间:2016-02-25 20:54:58

标签: php arrays session-variables

我有一个存储数组的会话变量。现在,在另一个PHP页面中,我想逐行打印这些数组值...就像Customer 1: Change is: 0.0 Expected is 0.0 Customer 2: Change is: 10.0 Expected is 10.0 Customer 3: Total Sales: 209.75 Payment Given: 220.0 Change is: 10.25 Expected is: 7.0 Daily Totals: Total Sales: $ 139.75 Number of Sales: 3.0 函数的结果一样

mysqli_fetch_array

在dists.php

$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");
    }
}

现在,我想使用这个$ result来通过不同行的列名访问数组的各个行和列

1 个答案:

答案 0 :(得分:1)

使用foreach()

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