duangewu5234 2015-10-16 22:25
浏览 41
已采纳

PHP是否在phpMyAdmin中重复具有相同名称的变量,或者它是否与print_r有关?

I was looking at the results of a mysql join in phpmyadmin, and comparing it to the php print_r dump, and noticed that the print_r seems to only use the first (row)"id" variable it comes to, and skips the second one. Is there a reason why the print_r wouldn't put something like a 'tablename."id"' instead of just eliminating the second tables "id" value?

PHPmyADMIN head dump:

  • id inst_id zip id inst_id skill

PHP sample dump:

  • Array ( [id] => 1 [inst_id] => 1 [zip] => 23456 [skill] => meow )
  • 写回答

1条回答 默认 最新

  • doudui6756 2015-10-16 22:30
    关注

    print_r just prints the array as it is, and apparently it only has those 4 indexes with the specified values.

    The problem is in the query itself. Table names or table aliases are not returned in the field name, so you get two fields named id. Since an array cannot have the same key twice, one of the two is just skipped.

    So to solve it, change the query by specifying an alias for the field itself:

    SELECT
      t1.id as t1_id, -- Key will be t1_id
      t2.id as t2_id, -- Key will be t2_id
      .. other fields ..
    FROM
      .. etcetera ...
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题