Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>That's because products_name and products_description is in table products_description (or to be more specific in TABLE_PRODUCTS_DESCRIPTION), not in table products (TABLE_PRODUCTS).</p> <p>To get all basic information (except attributes) You should execute following query:</p> <pre><code>$q = $db-&gt;Execute("SELECT * FROM " . TABLE_PRODUCTS . " p LEFT JOIN " . TABLE_PRODUCTS_DESCRIPTION . " pd ON(p.products_id = pd.products_id) WHERE language_id = " . (int)$_SESSION['languages_id']); $items = array(); while(!$q-&gt;EOF) { // let's get all attribues for product $productInfo = $q-&gt;fields; $qattr = $db-&gt;Execute("SELECT * FROM " . TABLE_PRODUCTS_ATTRIBUTES . " WHERE products_id = " . (int)$q-&gt;fields['products_id']); $attr = array(); while(!$qattr-&gt;EOF) { $attr[] = $qattr-&gt;fields; $qattr-&gt;MoveNext(); } $productInfo['attributes'] = $attr; $items[] = $productInfo; $q-&gt;MoveNext(); } // now let's output it foreach($items as $item) { echo '&lt;p&gt;&lt;a href="index.php?main_page=product_info&amp;products_id='. $item['products_id'] .'"&gt;&lt;img src="images/'. $item['products_image'].'" alt="'. $item['products_name'].'" title="'. $items['products_name'].'" /&gt;&lt;/a&gt;'; echo $items['products_price'] . '&lt;/p&gt;'; } </code></pre> <p>Note however that this code does <strong>NOT</strong> get products from specific category - it gets all products, even those that are deactivated. There are several ways to get products from specific category but they vary in performance. Unfortunately there's no best way to do this because it depends on the data. If the products You wish to retrieve belong to category with categories_id of 5 and it's their primary category it's enough to add to first query "WHERE master_categories_id = 5". But if the category is not master category for those products things get bit more complicated because We need to access products_to_categories table which causes performance hit for sites with many products. If You don't know/don't care about performance that much You can change first query to: (assuming that You already know categories_id of Your category):</p> <pre><code>$q = $db-&gt;Execute("SELECT * FROM " . TABLE_PRODUCTS . " p LEFT JOIN " . TABLE_PRODUCTS_DESCRIPTION . " pd ON(p.products_id = pd.products_id LEFT JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c ON(p.products_id = p2c.products_id AND p2c.categories_id = YOUR_CATEGORY_ID) WHERE pd.products_id IS NOT NULL AND p2c.products_id IS NOT NULL AND language_id = " . (int)$_SESSION['languages_id']); </code></pre> <p>To get rid of inactive products execute</p> <pre><code>$q = $db-&gt;Execute("SELECT * FROM " . TABLE_PRODUCTS . " p LEFT JOIN " . TABLE_PRODUCTS_DESCRIPTION . " pd ON(p.products_id = pd.products_id LEFT JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c ON(p.products_id = p2c.products_id AND p2c.categories_id = YOUR_CATEGORY_ID) WHERE products_status = 1 AND pd.products_id IS NOT NULL AND p2c.products_id IS NOT NULL AND language_id = " . (int)$_SESSION['languages_id']); </code></pre> <p>(Actually check on pd.products_id IS NOT NULL is not needed because We already check pd.language_id.)</p> <hr> <p>EDIT Version without attributes</p> <pre><code>$q = $db-&gt;Execute("SELECT * FROM " . TABLE_PRODUCTS . " p LEFT JOIN " . TABLE_PRODUCTS_DESCRIPTION . " pd ON(p.products_id = pd.products_id) WHERE language_id = " . (int)$_SESSION['languages_id']); $items = array(); while(!$q-&gt;EOF) { $items[] = $q-&gt;fields; $q-&gt;MoveNext(); } // now let's output it foreach($items as $item) { echo '&lt;p&gt;&lt;a href="index.php?main_page=product_info&amp;products_id='. $item['products_id'] .'"&gt;&lt;img src="images/'. $item['products_image'].'" alt="'. $item['products_name'].'" title="'. $items['products_name'].'" /&gt;&lt;/a&gt;'; echo $items['products_price'] . '&lt;/p&gt;'; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload