duanbanfei2875 2014-09-26 02:13
浏览 23
已采纳

从查询输出中选择第一行因为名称相同或将其设置为变量名称

I use php-mysql

this is my output table on query because I use LEFT JOIN and have a null value Query = "Select * from table LEFT JOIN table2 ON table.ID=table2.ID"

and the ouput is

ID | ID   |
1  | NULL |

and if I get the datas from $row['id] using mysqli_fetch the thing that returns to me is NULL or "" and what I wanted to get the value is = 1

and I'm thinking that I'll just set the table.ID into variable but I don't know how

  • 写回答

1条回答 默认 最新

  • duanhao9176 2014-09-26 02:15
    关注

    You should use column aliases for the id column in the first table from the id column in the second table:

    select table.id as id1, 
           table2.id as id2
    from table 
        left join table2 on table.ID=table2.ID
    

    Then you can use the column alias in your php code to access that particular value.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳