doutangdan3588 2014-01-28 06:59
浏览 84
已采纳

使用$ pdo从2个表中获取相同ID的数据

I'm trying to get some dataa from a table, and search for another field on other table by the id i got on my first query

$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']; 
}

This works fine. But i have to

select value from oc_setting where store_id == oc_store.store_id and key == config_logo

and echo all togheter, like:

echo $row['name'].' '.$row['url']. ' '. $row['store_id']. ' ' .$row['value'];

I tried nested foeach (silly me :P) and also with the LEFT JOIN, but i'm afraid i couldn't get it working, maybe i'm missing the right sintax for that.... Any helps? Thank you all

  • 写回答

2条回答 默认 最新

  • douse8732 2014-01-28 07:04
    关注

    you probably mean you need

    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'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部