我创建了一个在 phpMyAdmin 中完美运行的查询,但是当我尝试在 .php 文件中调用它时,出现以下错误。
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 行之前的代码按应有的方式查找、返回并显示结果。