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
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'
It didn't work with left join?
I'm genuinely new here and I'd love to give it a shot.
SELECT st.*, se.value FROM oc_store st LEFT JOIN oc_setting se ON st.store_id = se.store_id AND se.key = config_logo;
That's it IMO. Hope it works :)
NOTE: I'm not sure about key = config_logo as where is config_logo is coming from or where it belongs from those two tables. Key, I'm assuming it belongs to oc_settings.