簡體   English   中英

如何獲得聯接操作的結果?

[英]How to get the result of the join operations?

每當我嘗試在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;`行中。

任何幫助將不勝感激。

嘗試更改此行:

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

對此:

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

該表的名稱不在結果中。 如果需要避免混淆,可以在SQL查詢中使用別名。

我不了解drupal,也不使用php,但是我會說:

移走father. $row->father.Subject_Code

child. $row->child.Subject_Category

因為父親和孩子只是數據庫別名。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM