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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:18:43+00:00 2026-05-13T22:18:43+00:00

I’m working on a multi dimensions array but i have a problem Imagine I

  • 0

I’m working on a multi dimensions array but i have a problem

Imagine I have a company that can order some furniture’s
Fx
5 chair of different type’s width different standard prices different discount (%) and a price after discount now what

If a company can choose 3 of the 5 chairs to their design range and add each chair thru as checkbox. Then I need to set a discount to that unit and a “final price” and I ned to do it repeatedly, so I could add more chairs later.

My thoughts is something like this

Note that it has to be able to add an empty field in discount if there is no discount and I have to be able to read the values of the given input on of the given unit

I hope that you can help me and thanks for trying
Mikkel

<?php
mysql_connect('localhost', 'root', '') or 
die("Could not connect: " . mysql_error());
mysql_select_db("hassberg");
?>

<?php

$furniture_id = $_POST['furniture_id'];
$discount = $_POST['discount'];
$netto_price = $_POST['netto_price'];

if (isset($furniture_id)){


$get_info = array($furniture_id, $discount, $netto_price); 

$counter = 0;
$counter2 = 0;
foreach($get_info as $shop){
    echo "id: " . $shop[$counter][$counter02]." costs ".$shop[0][1]." and you get ".$shop[0][2]."<br />";
$counter++;
    if ($counter2 > 3){
        $counter2 = 0;
    }
}

//OR

$shop2 = array($furniture_id, $discount, $netto_price); 

foreach ($row as $rows){
    echo "<li><b>The row number $rows</b>";
    echo "<ul>";

    for ($col = 0; $col < 3; $col++){
        echo "<li>".$shop2[$rows][$col]."</li>";
    }

    echo "</ul>";
    echo "</li>";
}
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>tester</title>
</head>
<body>

<form name="create01" method="post" action="<?php echo $PHP_SELF; ?> ">
<?php 
$result = @mysql_query("SELECT id
                       FROM furniture_model;");
if (mysql_num_rows($result) == 0) // Exits if your db table is empty{
  echo 'I have no rows to display';
  exit;
}
else{
while($row_model = mysql_fetch_assoc($result)){
    echo $row_model['id'].
        '<input type="checkbox" class="customer_rel_check" name="chosen_model_id[]" value="'.$row_model['id'].'" /> 
         <input type="text" name="discount[]" />% 
         <input type="text" name="netto_price[]" />€ <br />'; //netto_price will be cumulated of the standard price and the discount
}
}
?>

<input type="submit" name="send" value="create" />
</form>
</body>
</html>
  • 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-05-13T22:18:43+00:00Added an answer on May 13, 2026 at 10:18 pm

    Well I found one answer it’s not as perfect as I wanted it to be but I works so I’m happy

    I had to add a hidden field to my form containing the model_id again so I could match it with the model_id that the checkbox sends

    <?php
    mysql_connect('localhost', 'root', '') or 
    die("Could not connect: " . mysql_error());
    mysql_select_db("hassberg");
    
    $customer_id = 4;
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
    <head>
    <title>tester</title>
    </head>
    <body>
    <?php
    $sql = 'INSERT INTO tabelname (customer_id, model_id, discount, netto) VALUES ';
    
    if(isset($_POST['chosen_model_id']) && count($_POST['chosen_model_id']) > 0){
    $count = count($_POST['chosen_model_id']);
    $i = 1;
    foreach($_POST['chosen_model_id'] as $value){
        $key = array_search($value, $_POST['hidden_furniture_id']);
    
        $sql .= '(' . $customer_id . ',' . 
                  $_POST['hidden_furniture_id'][$key] ."," . 
                  $_POST['netto_price'][$key] ."," . 
                  $_POST['discount'][$key] . ")"; 
        $sql .= ($i<$count) ? ", " : "";
        $i++;
    }
        echo '<p>' . $sql . '</p>';     
    }
    ?>
    
    <form name="create01" method="post" action="<?php echo $PHP_SELF; ?> ">
    <?php 
    $result = mysql_query("SELECT id
               FROM furniture_model;");
    if (mysql_num_rows($result) == 0){ // Exits if your db table is empty
      echo 'I have no rows to display';
      exit;
    }else{
    while($row_model = mysql_fetch_assoc($result)){
        echo $row_model['id'].
            '<input type="checkbox" class="customer_rel_check" name="chosen_model_id[]" value="'.$row_model['id'].'" /> '.
            '<input type="text" name="discount[]" />% ' .
            '<input type="text" name="netto_price[]" />€ ' .
            '<input type="hidden" name="hidden_furniture_id[]" value="' . 
                        $row_model['id'] . '" /> <br />'; 
                        //netto_price will be cumulated of the standard price and the discount 
    }
    }
    ?>
    <input type="submit" name="send" value="create" />
    </form>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a multi-language website. I have a problem with the color of
I have a multi-dimensional array similar to the example below that I want to
I am working with a multi-dimensional array. How can I remove duplicates by value?
I'm working on a multi-project, and right now I have a structure that resembles
I'm working with an open-source CMS that uses some very big multi dimensional arrays/objects.
I have an app that shows store sales. It is a multi-dimensional array, so
I am working with multi-dimensional Numpy arrays. I have noticed some inconsistent behavior when
I'm working on something that loops over a potentially multi-dimensional array and I am
I am working on a multi-thread program, and have a question about where to
I'm working on a multi-monitor kiosk application that needs to run full-screen on both

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.