我正在尝试从一个表中获取一些数据a,并通过我在第一次查询中获得的 id 在另一个表中搜索另一个字段
$db = new PDO('mysql:host=localhost;dbname=xxxxx;charset=utf8', 'xxxxx', 'xxxx');
foreach($db->query('SELECT * FROM oc_store') as $row) {
echo $row['name'].' '.$row['url']. ' '. $row['store_id'];
}
这很好用。但我必须
select value from oc_setting where store_id == oc_store.store_id and key == config_logo
然后一起回显,比如:
echo $row['name'].' '.$row['url']. ' '. $row['store_id']. ' ' .$row['value'];
我尝试了嵌套的 foeach(愚蠢的我 :P)以及 LEFT JOIN,但恐怕我无法让它工作,也许我错过了正确的语法……有什么帮助吗?谢谢大家
最佳答案
你可能是说你需要
select se.value, st.name, st.url
FROM
oc_setting se
INNER JOIN
oc_store st
ON st.store_id = se.store_id and st.key = 'config_logo'
关于php - 从 2 个表中获取数据,与 $pdo 具有相同的 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21409077/