Jump to content

Put Arrays from $_POST in HTML Table


lazerweb

Recommended Posts

Hi,

 

I do a form post from one page1.php to page2.php

 

This is my php code on page2.php :

 

<?php

if ($_POST) {

    echo '<pre>';

    echo htmlspecialchars(print_r($_POST, true));

    echo '</pre>';

}

?>

 

It gives me this result:

 

Array

(

    [1] => Array

        (

            [item1] => Nails sml

            [Price1] => 10

            [Qty1] => 42

            [LineTotal1] => €420.00

        )

 

    [2] => Array

        (

            [item2] => Nails lrg

            [Price2] => 12

            [Qty2] => 35

            [LineTotal2] => €420.00

        )

 

    [3] => Array

        (

            [item3] => Nails brown

            [Price3] => 5

            [Qty3] => 14

            [LineTotal3] => €70.00

        )

 

    [4] => Array

        (

            [item4] => Black Nails

            [Price4] => 10

            [Qty4] => 15

            [LineTotal4] => €150.00

        )

 

    [5] => Array

        (

            [item5] => Rusted Nails

            [Price5] => 10

            [Qty5] => 15

            [LineTotal5] => €150.00

        )

 

    [Total4] => €1210.00

    [Client_Details] => Array

        (

            [Company] => Lazerweb

            [Contact] => theo

            [Tel] => 0114567890

            => theo@tm4y.co.za

            [Delivery_Address] => 822 Witwatersrand Ave,Strubensvalley,Gauteng,1735

 

Ok, so here is my problem:

 

I could simply do the following :

 

<?php

echo $_POST['1']['Item1'];

?>

 

but the problem is that the input boxes from page1.php where this post comes from :

 

[1] => Array

        (

            [item1] => Nails sml

            [Price1] => 10

            [Qty1] => 42

            [LineTotal1] => €420.00

 

etc. etc.

 

are created from a csv file (I loop through every row), so I do not know how many rows there will be. It can be 1 or 100.

Therefore  arrays 1 to 5 can be arrays 1 to 100.

The only arrays that are constant and will not change is  [Total4] and [Client_Details]

 

I therefore cannot hard code these values, how would I go about doing this?

 

Thx

Theo

Link to comment
Share on other sites

remove the appended number from the field names (so for example "Item1", "Item2" etc. becomes simply "Item") and then

$total4 = $_Post["Total4"];
$client_details = $_Post["Client_Details"];

unset($_Post["Client_Details"]);
unset($_Post["Total4"]);

foreach ($_Post as $inputgroup) {
  echo $inputgroup["Item"];
  echo $inputgroup["Price"];
  //...
}

Link to comment
Share on other sites

Hi, thank you for your help, however I get the following message:

 

Warning: Invalid argument supplied for foreach() in W:\www\checkout.php on line 76

 

This is the line: foreach ($_Post as $inputgroup) {

 

I suppose it should be $_POST and not $_Post ?

 

Theo

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.