douzhenyu6533 2014-07-19 15:51
浏览 271
已采纳

分离mysqli_fetch_array返回的两个数组

I have created this

while ($data = mysqli_fetch_array($course_result, MYSQLI_ASSOC)) {
    print_r($data['course']);   
}  

Which prints this:

Array ( 
     [user_id] => 57 
     [course] => 6 
)
Array ( 
     [user_id] => 57 
     [course] => 5 
)

How can I create two variables that are equal to the values of the 'course' fields. So ideally, variable x ends up equalling to 6 and variable y equals 5 (essentially what I'm asking is how to extract the value from the mysql arrays and putting it into a variable)?

  • 写回答

3条回答 默认 最新

  • dongmie3987067 2014-07-19 16:12
    关注

    There is no something as you called "mysql_arrays". They are normal arrays.

    You can do for example:

    $array = array();
    while ($data = mysqli_fetch_array($course_result, MYSQLI_ASSOC)) {
       $array[] = $data; // probably this way and not $array[] = $data['course'];
    }  
    
    $x = $array[0]['course'];
    $y = $array[1]['course'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作