Note that there are some explanatory texts on larger screens.

plurals
  1. POphp explode product array throwing up errors
    primarykey
    data
    text
    <p>I have set up an 'orders' page that should be pretty straight-forward, requiring a for each loop to generate past orders from the DB. Within each loop, there needs to be an explode to separate each item(,), then another explode to pull the details out of each item(-). I was wondering if anyone could tell me why I'm getting the error message "Warning: mysql_num_rows() expects parameter 1" at the end of each iteration of my foreach loop? It's particularly confusing for me because the code still works, which I don't think it should if the error was true.</p> <pre><code>&lt;?php $sql = "SELECT * FROM orders WHERE store='$user'"; $res = mysql_query($sql); $arrOrders = array(); while ($row = mysql_fetch_array($res)) { array_push($arrOrders, $row); } ?&gt; &lt;table width="85%" align="center" border="0" cellpadding="5"&gt; &lt;?php if (count($arrOrders) &gt; 0) { ?&gt; &lt;?php foreach ($arrOrders as $key =&gt; $value) { ?&gt; &lt;tr&gt; &lt;td valign="top" style="font-weight: bold"&gt; ID #&lt;?=$value['id']?&gt; &lt;/td&gt; &lt;td valign="top" style="font-weight: bold"&gt; Status: &lt;?=$value['status']?&gt; &lt;/td&gt; &lt;td valign="top" style="font-weight: bold"&gt; Order #&lt;?=$value['order_ref']?&gt; &lt;/td&gt; &lt;td align="left" valign="top" style="font-weight: bold"&gt; &lt;?php $tmpProds = explode(',', $value['products']); foreach ($tmpProds as $key2 =&gt; $value2) { $tmpProdInfo = explode('-', $value2); $sql2 = 'SELECT * FROM products_full WHERE id = ' . $tmpProdInfo[0]; $res2 = mysql_query($sql2); if (mysql_num_rows($res2) &gt; 0) { // THIS IS THE ROW THAT THE ERROR MESSAGE POINTS TO echo $tmpProdInfo[1] + $tmpProdInfo[2] . ' x &lt;a href="item_details.php?id=' . mysql_result($res2, 0, 'id') . '"&gt;' . mysql_result($res2, 0, 'alpha_code') . ' (' . trim(mysql_result($res2, 0, 'description')) . ')&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;'; } } ?&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="100%" colspan="5" align="center"&gt; &lt;hr style="width: 100%" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;?php } ?&gt; &lt;?php } else { ?&gt; &lt;tr&gt; &lt;td width="100%" align="center"&gt; There are currently no complete orders. &lt;/td&gt; &lt;/tr&gt; &lt;?php } ?&gt; &lt;/table&gt; </code></pre> <p>Thanks in advance, I think I've included everything that is relative but if anything else is needed please let me know.</p> <p>Joe</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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