Querying associated images in one table after querying products from another
<p>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.  </p>

<pre><code>&lt;?php 
    global $__CMS_CONN__;

    $sql = "SELECT * FROM ecom_products";
    $stmt = $__CMS_CONN__-&gt;prepare($sql);
    $stmt-&gt;execute(array($id));

    while ($row = $stmt-&gt;fetchObject()) {

        $imagesql = "SELECT * FROM ecom_product_images where id = $row-&gt;id &amp;&amp; where primaryImage = '1'";
        $imagestmt = $__CMS_CONN__-&gt;prepare($sql);
        $imagestmt-&gt;execute(array($id));
        $imageName = $imagestmt-&gt;fetchObject();

        echo '&lt;a href="'.URL_PUBLIC.$row-&gt;id.'"&gt;'.$row-&gt;productNm.'&lt;/a&gt;'.$imageName;

    }
?&gt;
</code></pre>
