Note that there are some explanatory texts on larger screens.

plurals
  1. POmysql fetch by data from other table
    primarykey
    data
    text
    <p>I have built a simple webshop, where i need to process ordered products. The order comes in very nice with the id of the ordered product.</p> <p>I want the name and price of the product displayed on the page where i show all details about of the order. Too bad it doesn't work..</p> <p>This is my attempt: </p> <p>code to fetch product(s) ordered:</p> <pre><code>$query2 = mysql_query("SELECT * FROM orders_products WHERE order_id='".$_GET['order']."'"); while ($line2 = mysql_fetch_assoc($query2)) { $row2[] = $line2; $smarty-&gt;assign('row2', $row2); } </code></pre> <p>(attempt to) fetch product name and price:</p> <pre><code>$query4 = mysql_query("SELECT * FROM products WHERE id ='".$row2['product_id']."'"); while ($line4 = mysql_fetch_assoc($query4)) { $row4[] = $line4; $smarty-&gt;assign('row4', $row4); } </code></pre> <p>displaying it (excuse me for some dutch words in the html):</p> <pre><code> &lt;div class="module"&gt; &lt;h2&gt;&lt;span&gt;Bestelde Producten&lt;/span&gt;&lt;/h2&gt; {section name=row2 loop=$row2} {section name=row4 loop=$row4} &lt;div class="module-table-body"&gt; &lt;table id="bestelling" class="bestelling"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th style="width:3%"&gt;#&lt;/th&gt; &lt;th style="width:10%"&gt;Naam&lt;/th&gt; &lt;th style="width:10%"&gt;Bedrag&lt;/th&gt; &lt;th style="width:3%"&gt;Aantal&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;{$row2[row2].id}&lt;/td&gt; &lt;td&gt;{$row4[row4].name}&lt;/td&gt; &lt;td&gt;{$row4[row4].price}&lt;/td&gt; &lt;td&gt;{$row2[row2].product_amount}&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt;&lt;/br&gt; &lt;p&gt;&lt;strong&gt;Totaal: &lt;/strong&gt;&lt;/br&gt; &lt;strong&gt;BTW (21%): &lt;/strong&gt;&lt;/p&gt; &lt;/br&gt; &lt;p&gt;&lt;strong&gt;Totaal Inclusief BTW: &lt;/strong&gt;&lt;/p&gt; {/section} &lt;div style="clear: both"&gt;&lt;/div&gt; &lt;/div&gt; &lt;!-- End .module-table-body --&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>orders_products table:</p> <p>id order_id product_id product_amount </p> <p>products table:<br> id category_id name description slug price in_stock </p> <hr> <p>Thanks guys for your answers! Kami's code worked out for me.</p> <p>How i have it now: </p> <pre><code>$queryx = mysql_query("SELECT * FROM products inner join orders_products on products.id = orders_products.product_id WHERE order_id = '".mysql_real_escape_string($_GET['order'])."'"); while ($linex = mysql_fetch_assoc($queryx)) { $rowx[] = $linex; $smarty-&gt;assign('rowx', $rowx); } </code></pre> <p>Do you think this is safe? I will start using mysqli or PDO eventually, but i find it too dificult as i am still a beginner..</p> <p>Do you know any good guides about securing php -> mysql?</p> <p>Thanks so far!</p>
    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.
    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