php
  • arrays
  • session-variables
  • 2016-02-25 17 views 2 likes 
    2

    我有一個會話變量存儲數組。現在,在另一個PHP頁面,我想打印按行這些數組值的行...就像從mysqli_fetch_array功能結果確實如何從具有數組的會話變量中獲取數據

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

    在dists.php現在

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

    ,我要使用此$結果通過不同的行

    +0

    你可以給你的問題添加一些代碼嗎?你可能不得不考慮序列化,但我不完全確定。 – Maximus2012

    +0

    數組的會話變量是什麼樣的? – Maximus2012

    +0

    我在一個頁面和另一個頁面中將查詢結果存儲在會話變量中,我想使用此會話變量來打印數據庫值,如特殊coumns中的值 –

    回答

    1

    的列名來訪問各行和陣列的列使用foreach()

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

    @Vyshnavi Samudrala ...並將'$ _SESSION ['arrrows'] = $ arr_row;'行移至'while()'塊之後。 –

    相關問題