0
我有关于Drupal 7 Mysql查询特别是在左加入这个问题。左加入Drupal 7
我发现这个解决方案,但我似乎无法将它应用于我的问题,因为我不知道语法如何。
https://drupal.stackexchange.com/questions/4317/how-do-i-write-a-left-join-query
这是我上面的链接上找到了解决办法。
$terms = db_select('taxonomy_index', 'ti')
->fields('ti', array('tid', 'name'))
->leftJoin('taxonomy_term_data', 'ttd', 'ti.tid = ttd.tid')
->condition('vid', 2)
->condition('nid', $nid)
->execute();
foreach ($terms as $term) {
// $term contains the object for the taxonomy term.
}
然而,我如何将它应用到我的查询有问题。
这是我在MySQL上的LEFT JOIN查询。
$query = "SELECT sweep_table.end_offer, sweep_table.title, embed.fbp_id, embed.sweep_stat
FROM sweep_table, embed
WHERE sweep_table.uid=embed.uid AND sweep_table.promo_id=embed.sweep_id";
我已经做了第几行,但其余的,我不知道如何。
$terms = db_select('sweep_table', 'embed')
->fields('sweep_table', array('end_offer', 'title'))
->fields('embed', array('fbp_id', 'sweep_stat'))
->leftJoin('taxonomy_term_data', 'ttd', 'ti.tid = ttd.tid') //Don't know how to apply to my query.
->condition('vid', 2)
->condition('nid', $nid)
->execute();
foreach ($terms as $term) {
}
此外,想知道我成功后,如何检索数据左加入它?
如果你能帮助我,我会很高兴。
为什么不简单地执行构建它的SQL语句instat? – rekire 2013-02-13 06:15:17
它工作吗? 虽然我不知道它是否存在,但是想知道如何检索数据? 虽然“echo $ term-> sweep_table-> end_offer”不起作用 – 2013-02-13 06:24:42