down00112 2013-07-24 10:18
浏览 44
已采纳

数组数据如何存储在会话中

I have a challenge in getting back the array i stored in a session. I stored the array in a array like this

$downlines = '2,3,4,5,6,7,8';
$_SESSION['downline'] = $afrisoft->dbarray("SELECT username, email FROM users WHERE id IN $downlines")

When i print_r the session i get this

Array (
      [0] => Array (
                   [username] => mcbel 
                   [email] => firstmail@gmail.com
                   )
      [1] => Array (
                   [username] => bimibola
                   [email] => secondmail@yahoo.com
                   )
      [2] => Array (
                   [username] => shadie
                   [email] => thirdmail@gmail.com
                   )
      [3] => Array (
                   [username] => Hifee
                   [email] => ife@ife.net
                   )
      )

What i intend to achieve is to get the data stored in ['usernmae'] and ['email'], however when i try to print_r($_SESSION['downline']['username']) and print_r($_SESSION['downline']['email']) it returns no values.

I'll appreciate any help i can get on this.

  • 写回答

2条回答 默认 最新

  • dongqiulei1987 2013-07-24 10:20
    关注

    You have an array that is returned by your function. you can access the first element of that array by $_SESSION['downline'][0]['username']

    you can access the full results by traversing through $_SESSION['downline'] by doing

    foreach ($_SESSION['downline'] as $item) {
       echo $item['username']
    } 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化