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 7795027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:56:50+00:00 2026-06-01T22:56:50+00:00

I have a code that takes posted data from form A and then find

  • 0

I have a code that takes posted data from form A and then find the prices of goods and display them. Now i need to do more with the following data in the body of the 2nd form:
Item name
Item Qty
Item Price

The code is here:

<?php
echo "<div style='width:30%; height:auto; border: 2px solid;'>";
    echo "<h1>The Items Are...</h1><br>";
    //array that will hold the sum of each item cost
    $totalAmountArray = array();

    foreach ($_POST['basket'] as $name => $value) 
    {
        //indexer for totalAmountArray
        $i=0;
        if($value > 0){
                //echo $name . ": " . $value . "<br>";

            $itemPrice;
            //reassign 
            $itemName = $name;

            $itemQty = $value;
            //sql connection..
            mysql_connect();
            mysql_select_db("xxxxxx");
            $result = mysql_query("SELECT * FROM pricing WHERE item = '".$name."'");
            while($row = mysql_fetch_array($result)){
                $itemPrice = $row['price'];
                /*DEBUGGING*/
                echo "Item Name: <b>".$itemName . " </b>@ ";
                echo "<b>".$itemPrice ." </b>X ".$itemQty."<br>";
            }//end of while loop

            //multiply to get total for this item - store in temp
            $temp = $itemQty * $itemPrice;
            //store temp at index i in totalAmountArray
            array_push($totalAmountArray, $temp);
            unset($result);
            unset($itemPrice);
            unset($itemQty);
            unset($temp);
        }//end of if-statement
    }//end of foreach
    echo "<h1>Total Amount:<br></h1> ";
    //print_r($totalAmountArray);
    $sum;
    foreach($totalAmountArray as $perItemPrice){
        $sum += $perItemPrice;
    }
    echo "<b>SR. ".$sum."</b>";
echo "</div>";
?>

I am thinking of storing all the details returned from above foreach’s into multidimensional array to have something like this:

[0] => itemName => itemQty => itemPrice <br>
[1] => itemName => itemQty => itemPrice <br>
[2] => itemName => itemQty => itemPrice <br>
[3] => itemName => itemQty => itemPrice <br>
.....

would this be the best way? and how can it be done? I am really unfamiliar with multidimensional arrays in practice (only in theory).

Thanks a lot for the help and advice,

  • 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-01T22:56:53+00:00Added an answer on June 1, 2026 at 10:56 pm

    I may be wrong but since you want an advise I just do not see the point on why would you use a two dimensional array in this situation (although I may misunderstood your question and may wrong but I think the best way to solve your problem is to create a class Item in that class has a variables itemName itemQty itemPrice and then store information about every object item in to an array

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have this code that takes care of command acknowledgment from remote computers,
I have a piece of code that takes several rows from a database and
I have a code at the moment that takes a line from a .txt
I have the following code that takes a double value and converts it to
I have this small piece of code that basically takes a list and runs
I have the following code print Starting stage 1<br> # Something that takes about
Does anyone have some code that will take a TimeZoneInfo field from .NET and
I have to take over and improve/finish some code that transforms Java objects from
I have a generic dispatcher that takes in parameters and then make $.ajax() As
I have written code to perform a function that could take a while to

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.