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

  • Home
  • SEARCH
  • 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 7854099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:55:58+00:00 2026-06-02T19:55:58+00:00

I am developing an ordering page in PHP for some products. The user needs

  • 0

I am developing an ordering page in PHP for some products. The user needs to be able to select multiple types of products, so checkboxes will be necessary in the HTML form.

I’ve established an array for the checkboxes via the “name” attribute.

My problem is, I want to display what the user has selected on a confirmation page, so I’d like the “value” of those checkboxes to ultimately return a product name AND a product price. As far as I can tell I’m going to be stuck with one value only, so I’ve attempted to get around this:

<?php
//variables for the array and the count
$parray = $_POST['product'];
$pcount = count($parray);

//arrays for each product's information; i've only listed one for simplicity
$br = array("Big Red", 575);

/*The idea for this was for each product ordered to add a line giving the product information and display it. When the $key variable is assigned, it is stored simply as a string, and not an array (yielding [0] as the first letter of the string and [1] as the second), which I expected, but my general idea is to somehow use $key to reference the above product information array, so that it can be displayed here*/


if (!empty($parray))
{
    for ($i=0; $i < $pcount; $i++)
{
    $key = $parray[i];
    echo "<tr><td height='40'></td><td>" . $key[0] . "</td><td>" . $key[1] . "</td></tr>";

}
}
?>

Is there anyway to make my $key variable actually act as if it is the array’s name it is set to?
If not, is there any good way to do this?

  • 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-02T19:56:00+00:00Added an answer on June 2, 2026 at 7:56 pm

    So in your HTML table, you’ll need to render each checkbox like this:

    <input type="checkbox" name="selectedIDs[]" value="$key" />
    

    where $key is the item number.

    Then, in your PHP, you’ll have a $_POST["selectedIDs"] variable, which is an array of all the item numbers that were checked.

    Assuming you’ve got a product list array like this:

    $products = array( 1 => array("Big Red", 575), 2 => array("Spearmint", 525));
    

    You can then print a list of the selected products using a loop like this:

    for($i = 0; $i < count($_POST["selectedIDs"]); $i++) {
        $key = $_POST["selectedIDs"][$i];
        $product = $products[$key];
        echo "<tr><td height='40'></td><td>" . $product[0] . "</td><td>" . $product[1] . "</td></tr>";
    }
    

    The only real difference between this and what you wrote is that my $products array is two-dimensional, and my $key is used to grab the relevant product from the $products array.

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

Sidebar

Related Questions

I am developing a stock ordering system in PHP/MySQL. Products can have multiple suppliers.
with GWT 2.4 , i'm developing a web ordering system wherein user can select
Developing a project of mine I realize I have a need for some level
Developing a multilingual application in VB.Net 2008, Im able to add resources to forms
developing an application in Access. The access file will be located on a db
Developing an app where all tabular data is returned as an object. Some cells
Developing with Google Maps v3. For some sort of reason, my custom marker icon
Developing an application for Android, i want to record data that will be usefull
I am developing an E-Commerce application. But the problem is when user adds a
Developing a series of POCOs on my project, and just realized that some of

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.