INNER JOIN WITH WHERE MYSQL

Asked

Viewed 813 times

1

I have a foreach that runs each product, then I would like to make a query in two tables from that ID, only I’m not getting, what I’m doing wrong?

$collection = Mage::getModel('catalog/product')->getCollection();
foreach ($collection as $key => $produto) {
$id = $produto->getId();

$produto_loaded = Mage::getModel('catalog/product')->load($id);

$id_prd = $produto_loaded->getId();  

$teste = $id_prd;
$link = mysqli_connect('localhost','root','','teste2');
$link->set_charset("utf8");
$query =
"SELECT catalog_product_website.website_id as websiteid, catalog_category_product.category_id as categoria, catalog_category_product.position as positioncat
FROM catalog_product_website
INNER JOIN catalog_category_product
ON catalog_product_website.websiteid = catalog_category_product.product_id
WHERE n.websiteid = '$teste'";
$select = mysqli_query($link, $query);
while ($row = mysqli_fetch_array($select)) {
$test = array(
$row['websiteid'],
$row['categoria'],
$row['positioncat']);
print_r($test);
}

1 answer

1


SELECT a.website_id as websiteid, 
b.category_id as categoria, 
b.position as positioncat
FROM catalog_product_website a
INNER JOIN catalog_category_product b
ON a.website_id = b.product_id
WHERE a.websiteid = '$teste'";

Test this script

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.