HTML form in while loop, how to transfer data from each item?

Sabrine Andersen

I have tried to solve it and look around but not even sure what I should be searching for.

I have made a product grid through a while loop, in the loop with each product and input-tag has been used for users to mark how many items of each product is wanted.

The product grid

However I have trouble distinguishing the value of each input field and what "name" it should be stored under to be able to retrieve it when running the second script of processing the order? I also need to be able to connect an id with each value.

The code for the grid: I know I need to make a unique name in the input name, however how and which makes sense?

<div id="content">
    <h1>Products</h1>

    <form action="processorder.php" method="post">
    <table align="center">
        <?php

        $db = include "connect2db.php"; 

        mysqli_set_charset($db,"utf8");

        $query = 'SELECT * FROM products_josie';

        $result = $db->query($query);


        $count = 0;
        while($res=$result->fetch_assoc())
        {
            if($count==3)
            {
               echo '</tr>';
               $count = 0;
            }
            if($count==0)
               echo '<tr>';
               echo '<td>';
               ?>

               <a href="productsdetails.php?clickedid=<?php echo $res['product_id']?>">
               <img src="products/<?php echo $res['photo']; ?>" width="200" height="150"/>
               </a>
               <br/>
            <?php
            echo '<p>';
            echo $res['product_name'];
            echo '</br>';
            echo 'DKK ';
            echo $res['price'];
            echo '</p>';
            echo '<p>';
            echo '<input type="number" name="amount" min="0"';
            echo '</p>';
            $count++;
            print '</td>';
        }
        if($count>0)
            print '</tr>';
        ?>
    </table>

    <input type="submit" value="Submit Order">
    </form>
</div>
TBowman

I think what you are looking for is how to get the amounts for different products. If so, something like this might do it:

$prod = $res['product_name'];
echo '<input type="number" name="amount[$prod]" min="0"';

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

HTML Form data from checkboxes within while loop

From Dev

how to remove an item from class list while using for-each loop?

From Dev

How to cycle through each item in a hashmap using a while loop

From Dev

How to Fetch data from while loop inside a while loop

From Dev

How to get data transfer from the form into database Laravel 5

From Dev

How to offset rows from each other during a While Loop in PHP

From Dev

how to GET data from mongodb and transfer it to Html page using nodeJS?

From Dev

How can I transfer data from html to php in this case

From Dev

how to GET data from mongodb and transfer it to Html page using nodeJS?

From Dev

How can I transfer data from html to php in this case

From Dev

how to transfer data from one html page to another using javascript

From Dev

how to process json data through an .each loop into html table

From Dev

Remove comma from last item in while loop

From Dev

Form is presenting same data in php while loop

From Dev

Form inside a php while loop not posting data

From Dev

How to get dynamic data from ADO.NET in while loop

From Dev

how to remove last comma from php while loop for json data

From Dev

How to get dynamic data from ADO.NET in while loop

From Dev

How to fetch data from table using while loop?

From Dev

how to loop through each item of a MongoCollection?

From Dev

How to loop through a function for each item in list?

From Dev

How to append each item in the list using loop?

From Dev

Data transfer from tiny MCE in HTML to php?

From Dev

How to transfer data to the controller from view outside the form or dont create new input

From Dev

How to save results for each while loop in python?

From Dev

how to get each item without using a loop from string array in c#

From Dev

How to Select an item from Dropdown Menu using while Loop in Php Mysql

From Dev

How can i loop each item of list in each column?

From Dev

how to extract data from html table using jQuery each function

Related Related

  1. 1

    HTML Form data from checkboxes within while loop

  2. 2

    how to remove an item from class list while using for-each loop?

  3. 3

    How to cycle through each item in a hashmap using a while loop

  4. 4

    How to Fetch data from while loop inside a while loop

  5. 5

    How to get data transfer from the form into database Laravel 5

  6. 6

    How to offset rows from each other during a While Loop in PHP

  7. 7

    how to GET data from mongodb and transfer it to Html page using nodeJS?

  8. 8

    How can I transfer data from html to php in this case

  9. 9

    how to GET data from mongodb and transfer it to Html page using nodeJS?

  10. 10

    How can I transfer data from html to php in this case

  11. 11

    how to transfer data from one html page to another using javascript

  12. 12

    how to process json data through an .each loop into html table

  13. 13

    Remove comma from last item in while loop

  14. 14

    Form is presenting same data in php while loop

  15. 15

    Form inside a php while loop not posting data

  16. 16

    How to get dynamic data from ADO.NET in while loop

  17. 17

    how to remove last comma from php while loop for json data

  18. 18

    How to get dynamic data from ADO.NET in while loop

  19. 19

    How to fetch data from table using while loop?

  20. 20

    how to loop through each item of a MongoCollection?

  21. 21

    How to loop through a function for each item in list?

  22. 22

    How to append each item in the list using loop?

  23. 23

    Data transfer from tiny MCE in HTML to php?

  24. 24

    How to transfer data to the controller from view outside the form or dont create new input

  25. 25

    How to save results for each while loop in python?

  26. 26

    how to get each item without using a loop from string array in c#

  27. 27

    How to Select an item from Dropdown Menu using while Loop in Php Mysql

  28. 28

    How can i loop each item of list in each column?

  29. 29

    how to extract data from html table using jQuery each function

HotTag

Archive