sis*_*sko 4 php database drupal drupal-7
我试图使用以下代码从同一个数据库查询中的两个数据库表中检索信息:
$query = db_select('webform_questionnaire_fieldset', 'wqf');
$query->join('webform_component', 'wc', 'wqf.cid = wc.cid');
$query->fields('wqf')
->fields('wc')
->condition('wqf.cid', $cid, '=')
->condition('wqf.nid', $nid, '=')
->condition('wqf.cid', 'wc.cid', '=')
->execute()
->fetchAll();
Run Code Online (Sandbox Code Playgroud)
我得到的输出与数据库数据不相似,但看起来更像数据库元数据,如下所示:
SelectQuery::__set_state(array(
'fields' =>
array (
),
'expressions' =>
array (
),
'tables' =>
array (
'wqf' =>
array (
'join type' => NULL,
'table' => 'webform_questionnaire_fieldset',
'alias' => 'wqf',
'condition' => NULL,
'arguments' =>
array (
),
'all_fields' => true,
),
'wc' =>
array (
'join type' => 'INNER',
'table' => 'webform_component',
'alias' => 'wc',
'condition' => NULL,
'arguments' =>
array (
),
'all_fields' => true,
),
),
'order' =>
array (
), ......
Run Code Online (Sandbox Code Playgroud)
谁能告诉我我做错了什么?
添加condition到join语句.喜欢on table1.id = table2.id,然后添加$result = $query->execute()->fetchAll();
$query = db_select('webform_questionnaire_fieldset', 'wqf');
$query->join('webform_component', 'wc', 'wqf.cid = wc.cid');
$query->fields('wqf')
->fields('wc')
->condition('wqf.cid', $cid, '=')
->condition('wqf.nid', $nid, '=')
->condition('wqf.cid', 'wc.cid', '=');
$result = $query->execute()->fetchAll();
Run Code Online (Sandbox Code Playgroud)
希望这有助于......穆罕默德.
| 归档时间: |
|
| 查看次数: |
1359 次 |
| 最近记录: |