Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8194089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:42:11+00:00 2026-06-07T04:42:11+00:00

i have a two dimensional array, and i want to retrieve its value in

  • 0

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

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, array given in

this is the code i’m using to assign values to a multidimensional session.

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));
}
    }

and after assigning i’m trying to retrieve those date with these codes

<?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;
    }



?>  

i can’t figure out where the error is. can anyone help me please

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:42:12+00:00Added an answer on June 7, 2026 at 4:42 am

    You are trying to loop an array as if it were a database resultset. You actually don’t need a loop here, you can just access the values directly, by key.

    For example, try this:

    echo $each_item['date'];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of two dimensional Arrays. I want to create a new
I want to have static and constant two dimensional array inside a class. The
I have a two dimensional array with coordinates and i want to make the
I have a 3 dimensional array. I want to assign only the first two
I have a two dimensional array having elements of a matrix I want to
I have a two dimensional array in php and I want to get the
I have two dimensional float array as below {0.2,0.0,0.3,0.0,0.0} {0.4,0.1,0.0,0.0,0.9} {0.0,0.0,0.0,0.3,0.6} I want to
I have defined two dimensional array using following definition typedef std::vector<std::vector<short> > table_t; Can
I have a two dimensional array that is holding the value of 5 cards.
I have a array of two dimensions object[,] data; . I want to convert

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.