duandangqin0559 2013-08-06 15:47
浏览 44
已采纳

查询加入同一个表3次

I have created a query that works perfectly in phpMyAdmin, however when I try to call it in a .php file I get the following error.

Undefined variable: mothers_name in C:\wamp\www\Family_Tree\showfamily.php on line 56

My code is:

$select_query = "SELECT a.id, CONCAT( a.surname,  ', ', a.first_names ) AS child_name, " . 
"CONCAT( b.surname,  ', ', b.first_names ) AS mothers_name, " .
"CONCAT( c.surname, ', ', c.first_names ) AS fathers_name " .
"FROM family_members a " .
"INNER JOIN family_members b ON a.mother_id = b.id " .
"INNER JOIN family_members c ON a.father_id = c.id" .
"WHERE a.id = " . $user_id;

Am I getting this error because the tables "a","b" and "c" and the fields "mother_id" and "father_id" doesn't exist until the SQL is called through the mysql_query($select_query) function.

The code before line 56 looks up, returns and displays the results as they should.

  • 写回答

2条回答 默认 最新

  • douchuanchai2793 2013-08-06 15:50
    关注
    ..._id = c.id" .               // <-- you forgot a space, results in c.idWHERE
    "WHERE a.id = " . $user_id;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因