我有一个二维数组,我想将其值检索到单独的变量中。我正在使用这些代码,但它给了我一个错误说
警告:mysql_fetch_assoc() 期望参数 1 是资源,数组在
这是我用来为多维会话分配值的代码。
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"]) < 1 ) {
// Run if the bill is empty or not set
$_SESSION["bill_array"]= array(1 => array("date"=> $date, "billnmbr"=> $billnmbr, "itemcode"=> $itemcode, "itemname"=> $itemname, "exdate"=> $exdate, "eachprice"=> $eachprice, "itmtotal"=> $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" && $value == $itemcode){
// That item is in cart already so push a error message in to screen
$wasFound = true;
?>
<script type="text/javascript">
var error = "<?= $wasFound ?>";
if(error == "true") {
alert("You trying to add same item twice")
}
</script>
<?php
}//close if condition
}//close while loop
}//close foreach loop
if($wasFound==false){
array_push($_SESSION["bill_array"],array("date"=> $date, "billnmbr"=> $billnmbr, "itemcode"=> $itemcode, "itemname"=> $itemname, "exdate"=> $exdate, "eachprice"=> $eachprice, "itmtotal"=> $itmtotal));
}
}
分配后我试图用这些代码检索那些日期
<?php
$cartOutput="";
if(!isset($_SESSION["bill_array"]) || count($_SESSION["bill_array"]) < 1 ) {
$cartOutput = "<h2 align='center'> Bill is still empty </hd>";
}
else {
$i = 0;
foreach ($_SESSION["bill_array"]as $each_item ) {
$i++;
echo $cartOutput = "<h2> Bill item $i </h2>";
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;
}
?>
我不知道错误在哪里。谁能帮帮我