0

每当我尝试在 drupal 的功能模块中执行此 sql 查询时,我都无法获得结果,但是当我尝试在 MySQL 中执行此操作时,我可以查看结果。我的代码如下所示:

 function _get_subject_sub_category() {

  $options = array();
  $sql = "SELECT father.Subject_Code, child.Subject_Category 
FROM {subjects} as child 
INNER JOIN {subjects} as father ON (child.Parent_Category = father.Subject_Code
AND child.Level =2 )";

  $result = db_query($sql);
  foreach ($result as $row) {


     $options[$row->father.Subject_Code] = $row->child.Subject_Category;

  }
  return $options;
  }

我遇到的错误在 $options[$row->father.Subject_Code] = $row->child.Subject_Category;` 行中。

任何帮助将不胜感激。

4

2 回答 2

1

尝试更改此行:

$options[$row->father.Subject_Code] = $row->child.Subject_Category;

对此:

$options[$row->Subject_Code] = $row->Subject_Category;

表的名称不在结果中。如果需要避免混淆,可以在 SQL 查询中使用别名。

于 2013-01-18T08:22:59.987 回答
1

我不知道drupal,也不使用php,但我会说:

删除 father._$row->father.Subject_Code

child.$row->child.Subject_Category

因为父亲和孩子只是数据库别名。

于 2013-01-18T08:23:03.690 回答