我创建了一个在phpMyAdmin中完美工作的查询,但是当我尝试在.php文件中调用该查询时,出现以下错误。加入同一表的查询3次
Undefined variable: mothers_name in C:\wamp\www\Family_Tree\showfamily.php on line 56
我的代码是:
$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;
我会收到这个错误,因为表 “A”, “B” 和 “C” 和字段 “mother_id” 和 “father_id” 不直到通过mysql_query($ select_query)函数调用SQL。
第56行之前的代码查找,返回并显示结果。