Note that there are some explanatory texts on larger screens.

plurals
  1. POretrieving data from multidimensional array with php
    primarykey
    data
    text
    <p>i have a two dimensional array, and i want to retrieve its value in to separate variables. i'm using these codes, but it gives me a error saying</p> <p>Warning: mysql_fetch_assoc() expects parameter 1 to be resource, array given in</p> <p>this is the code i'm using to assign values to a multidimensional session. </p> <pre><code>if(isset($_POST['adnother'])) { $date = $_POST['date']; $billnmbr = $_POST['billnmbr']; $itemcode = $_POST['itemcode']; $itemname = $_POST['itemname']; $exdate = $_POST['exdate']; $eachprice = $_POST['eachprice']; $itmtotal = $_POST['itmtotal']; $wasFound=false; $i=0; //if the bill session variable is not set or cart array is empty if(!isset($_SESSION["bill_array"]) || count($_SESSION["bill_array"]) &lt; 1 ) { // Run if the bill is empty or not set $_SESSION["bill_array"]= array(1 =&gt; array("date"=&gt; $date, "billnmbr"=&gt; $billnmbr, "itemcode"=&gt; $itemcode, "itemname"=&gt; $itemname, "exdate"=&gt; $exdate, "eachprice"=&gt; $eachprice, "itmtotal"=&gt; $itmtotal)); } else { // Run if the bill has at least one item in it foreach($_SESSION["bill_array"] as $each_item) { $i++; while(list($key,$value)=each($each_item)){ if($key=="itemcode" &amp;&amp; $value == $itemcode){ // That item is in cart already so push a error message in to screen $wasFound = true; ?&gt; &lt;script type="text/javascript"&gt; var error = "&lt;?= $wasFound ?&gt;"; if(error == "true") { alert("You trying to add same item twice") } &lt;/script&gt; &lt;?php }//close if condition }//close while loop }//close foreach loop if($wasFound==false){ array_push($_SESSION["bill_array"],array("date"=&gt; $date, "billnmbr"=&gt; $billnmbr, "itemcode"=&gt; $itemcode, "itemname"=&gt; $itemname, "exdate"=&gt; $exdate, "eachprice"=&gt; $eachprice, "itmtotal"=&gt; $itmtotal)); } } </code></pre> <p>and after assigning i'm trying to retrieve those date with these codes </p> <pre><code>&lt;?php $cartOutput=""; if(!isset($_SESSION["bill_array"]) || count($_SESSION["bill_array"]) &lt; 1 ) { $cartOutput = "&lt;h2 align='center'&gt; Bill is still empty &lt;/hd&gt;"; } else { $i = 0; foreach ($_SESSION["bill_array"]as $each_item ) { $i++; echo $cartOutput = "&lt;h2&gt; Bill item $i &lt;/h2&gt;"; while($row=mysql_fetch_assoc($each_item)){ $date1=$row["date"]; $billnmbr1=$row["billnmbr"]; $itemcode1=$row["itemcode"]; $itemname1=$row["itemname"]; $exdate1=$row["exdate"]; $eachprice1=$row["eachprice"]; $itmtotal1=$row["itmtotal"]; } } echo $date1; echo $billnmbr1; echo $itemcode1; echo $itemname1; echo $exdate1; echo $eachprice1; echo $itmtotal1; } ?&gt; </code></pre> <p>i can't figure out where the error is. can anyone help me please </p>
    singulars
    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