我有兩個查詢將 4 個表連接在一起。第四個表是從第一個表讀取的值。到目前為止,我一直將該值讀入一個變量,然后在第二個查詢中使用該變量,但我想知道是否可以將其合并到一個查詢中。這是我的查詢($node_type_name 是從調用函數傳入的):$this->read_db->select('id, head_node_id, data_table_name'); $this->read_db->from('node_type'); $this->read_db->where('name', $node_type_name); $Q = $this->read_db->get(); $table_name = $Q->row_array()['data_table_name']; $field_name = $table_name . '.node_id'; $this->read_db->select('node.id, node.name, node.is_head_node, node.node_type_id, node_link.parent_node_id, ' . $table_name . '.id, ' . $table_name . '.node_id'); $this->read_db->from('node'); $this->read_db->join('node_link', 'node_link.child_node_id = node.id'); $this->read_db->join($table_name, $field_name . ' = node.id'); $M = $this->read_db->get();該函數是一個通用函數,因此某人可以將 locations 發送到 $node_type_name 或 organizations,并且查詢將加入與這些名稱關聯的表。目前只有兩種“類型”,但我們將來可能會添加更多,因此該功能需要是通用的。
- 1 回答
- 0 關注
- 154 瀏覽
添加回答
舉報
0/150
提交
取消