Querying associated images in one table after querying products from another

Posted by Andy on Stack Overflow See other posts from Stack Overflow or by Andy
Published on 2010-05-21T10:56:25Z Indexed on 2010/05/21 11:00 UTC
Read the original article Hit count: 178

Filed under:

I used this code to connect to a database and fetch results. This worked perfectly until i tried to work in another query to the images table to get associated images. I'm not very experienced with OO programming. So hopefully someone can see where ive gone wrong and help me out.

<?php 
    global $__CMS_CONN__;
    $sql = "SELECT * FROM ecom_products";
    $stmt = $__CMS_CONN__->prepare($sql);
    $stmt->execute(array($id));
    while ($row = $stmt->fetchObject()) {
            $imagesql = "SELECT * FROM ecom_product_images where id = $row->id && where primaryImage = '1'";
        $imagestmt = $__CMS_CONN__->prepare($sql);
            $imagestmt->execute(array($id));
            $imageName = $imagestmt->fetchObject();
        echo '<a href="'.URL_PUBLIC.$row->id.'">'.$row->productNm.'</a>'.$imageName;
    }
?>

© Stack Overflow or respective owner

Related posts about php