Solution 1 :

You mean

<?php
foreach ($csv as $order) : ?>
    <td style="vertical-align: top; width: 100%; text-align:right;">
        <b>Name:&nbsp;</b><br />
        <b>Phone:&nbsp;</b><br />
        <b>Email:&nbsp;</b><br />
        <b>Paid Via:&nbsp;</b><br />
        <b>Sold Via:&nbsp;</b><br />
        <b>User ID:&nbsp;</b><br />
        <b>Sales Rec:&nbsp;</b><br />
        <b>Order No.:&nbsp;</b>
    </td>
    <td style="vertical-align: top; width: 311px;"><?php echo $csv[0][3]; ?><br />
        <?php echo $order[13]; ?><br />
        <?php echo $order[4]; ?><br />
        <?php echo $order[32]; ?><br />
        eBay<br />
        <?php echo $order[2]; ?><br />
        <?php echo $order[0]; ?><br /> 
        <?php echo $order[1]; ?><br />
    </td>
<?php endforeach; ?>

BTW, don’t use the long-deprecated <b> tag (<strong> is preferred, if that’s what you mean; otherwise use CSS), and <br> doesn’t need a slash.

Problem :

Thanks to the most excellent help of the SO community I now have an auto-generated array that looks like so.. (looks like real data but has been anonymized)

Array
(
    [0] => Array
        (
            [0] => 15304
            [1] => 15-04478-27247
            [2] => mysuserid
            [3] => eric smith
            [4] => [email protected]
            [5] => 
            [6] => 27 Any Close
            [7] => 
            [8] => Manchester
            [9] => Greater Manchester
            [10] => M14 2RB
            [11] => United Kingdom
            [12] => eric spilsbury
            [13] => +44 7719 123456
            [14] => 27 Any Close
            [15] => 
            [16] => Manchester
            [17] => Greater Manchester
            [18] => M14 2RB
            [19] => United Kingdom
            [20] => Array
                (
                    [0] => 302804801330
                    [1] => 302804815489
                )

            [21] => Array
                (
                    [0] => CAUTION DRIVEN BY A BIKER  - Fun Vinyl Decal Sticker 4x4/Car/Lorry/Van/Camper
                    [1] => Warning Biker With an Attitude Annoy At Your Own Risk Car Vinyl Decal Sticker
                )

            [22] => 
            [23] => No
            [24] => Array
                (
                    [0] => 2
                    [1] => 1
                )

            [25] => Array
                (
                    [0] => £3.90
                    [1] => £1.95
                )

            [26] => £0.00
            [27] => 
            [28] => £0.00
            [29] => £0.00
            [30] => £3.90
            [31] => No
            [32] => PayPal
            [33] => 30-Jan-20
            [34] => 30-Jan-20
            [35] => 
            [36] => 
            [37] => 
            [38] => 31-Jan-20
            [39] => No
            [40] => 
            [41] => 
            [42] => 5LD87965090833954U
            [43] => Royal Mail 1st Class
            [44] => 
            [45] => Array
                (
                    [0] => 1711351782020
                    [1] => 1711351781020
                )

            [46] => 
            [47] => No
            [48] => 
            [49] => No
            [50] => 
            [51] => No
        )

    [1] => Array
        (
            [0] => 15121
            [1] => 25-04445-36722
            [2] => dopp69
            [3] => mart podd
            [4] => [email protected]
            [5] => 
            [6] => Via Riccione N. 20/18
            [7] => 
            [8] => Sa Tiacca Quartu S. Elena
            [9] => CA
            [10] => 09847
            [11] => Italy
            [12] => Podd Mart
            [13] => +39 342 000 9876
            [14] => Via Riccione N. 30/32
            [15] => 
            [16] => Sa Tiacca Quartu S. Elena
            [17] => CA
            [18] => 09847
            [19] => Italy
            [20] => 302667176336
            [21] => 2x Funny Car & Van or Camper WV Eyelash Vinyl Sticker Decal, Signs - Any Colour!
            [22] => 
            [23] => No
            [24] => 2
            [25] => £1.99
            [26] => £3.14
            [27] => 
            [28] => £0.00
            [29] => £0.00
            [30] => £7.12
            [31] => No
            [32] => PayPal
            [33] => 23-Jan-20
            [34] => 23-Jan-20
            [35] => 24-Jan-20
            [36] => 
            [37] => 
            [38] => 24-Jan-20
            [39] => Yes
            [40] => 
            [41] => 
            [42] => 25C157351T667760U
            [43] => Royal Mail International Standard
            [44] => 
            [45] => 1709118816020
            [46] => 
            [47] => No
            [48] => 
            [49] => No
            [50] => 
            [51] => No
        )

    [2] => Array
        (
            [0] => 15320
            [1] => 20-04482-41274
            [2] => wideboy3480
            [3] => BEN ROYLES
            [4] => [email protected]
            [5] => Yellow please
            [6] => 10
            [7] => Broomstick Close
            [8] => Okehampton
            [9] => Devon
            [10] => EX20 1FT
            [11] => United Kingdom
            [12] => Ben Royles
            [13] => +44 7876 401999
            [14] => 105
            [15] => Broomstick Close
            [16] => Okehampton
            [17] => Devon
            [18] => EX10 1WT
            [19] => United Kingdom
            [20] => 302713568952
            [21] => Junglist Soldier Car Window Laptop Wall Gift Drum Bass dnb Jungle Vinyl Sticker
            [22] => 
            [23] => No
            [24] => 1
            [25] => £1.99
            [26] => £0.00
            [27] => 
            [28] => £0.00
            [29] => £0.00
            [30] => £1.99
            [31] => No
            [32] => PayPal
            [33] => 01-Feb-20
            [34] => 01-Feb-20
            [35] => 03-Feb-20
            [36] => 
            [37] => 
            [38] => 
            [39] => No
            [40] => 
            [41] => 
            [42] => 7SD68673EE278782X
            [43] => Royal Mail 1st Class
            [44] => 
            [45] => 1711667179020
            [46] => 
            [47] => No
            [48] => 
            [49] => No
            [50] => 
            [51] => No
        )

        <!---And so on--->

The code used to generate this is as follows…

<?php
    function readCSV($csvFile)
    {
        $line_of_text = [];
        $file_handle = fopen($csvFile, 'r');
        fgetcsv($file_handle);
        fgetcsv($file_handle);
        fgetcsv($file_handle);
        while (!feof($file_handle)) {
            $tmp = fgetcsv($file_handle, 1024);

            if (isset($line_of_text[$tmp[0]])) {
                foreach ($tmp as $k => $v) {

                    if (array_key_exists($k, $line_of_text[$tmp[0]])) {
                        if (!is_array($line_of_text[$tmp[0]][$k])) {
                            $kVal = $line_of_text[$tmp[0]][$k];

                            $line_of_text[$tmp[0]][$k] = [];
                            $line_of_text[$tmp[0]][$k][] = $kVal;
                        }

                        $line_of_text[$tmp[0]][$k][] = $v;
                        $line_of_text[$tmp[0]][$k] = array_unique($line_of_text[$tmp[0]][$k]);
                        $line_of_text[$tmp[0]][$k] = array_filter($line_of_text[$tmp[0]][$k]);

                        if (count($line_of_text[$tmp[0]][$k]) == 1) {
                            $line_of_text[$tmp[0]][$k] = array_values($line_of_text[$tmp[0]][$k]);
                            $line_of_text[$tmp[0]][$k] = $line_of_text[$tmp[0]][$k][0];
                        }

                        if (empty($line_of_text[$tmp[0]][$k])) {
                            $line_of_text[$tmp[0]][$k] = null;
                        }

                    } else {
                        $line_of_text[$tmp[0]][$k] = null;
                    }
                }
                $line_of_text[$tmp[0]][0] = $tmp[0];

            } else {
                $line_of_text[$tmp[0]] = $tmp;
            }

        }

        fclose($file_handle);
        return array_filter(array_values($line_of_text));
    }

    // Set path to CSV file
    $csvFile = 'test.csv';
    $csv = readCSV($csvFile);

echo '<pre>';
print_r($csv);
echo '</pre>';

?>

What I want to do is use the data from these auto-generated arrays to auto-generate invoice pages that I have made using html/php markup.

I have been able to make an example targetting the data from the 1st entry [0] like in this example snippet…

    <td style="vertical-align: top; width: 100%; text-align:right;">
        <b>Name:&nbsp;</b><br />
        <b>Phone:&nbsp;</b><br />
        <b>Email:&nbsp;</b><br />
        <b>Paid Via:&nbsp;</b><br />
        <b>Sold Via:&nbsp;</b><br />
        <b>User ID:&nbsp;</b><br />
        <b>Sales Rec:&nbsp;</b><br />
        <b>Order No.:&nbsp;</b>
    </td>
    <td style="vertical-align: top; width: 311px;"><?php echo $csv[0][3]; ?><br />
        <?php echo $csv[0][13]; ?><br />
        <?php echo $csv[0][4]; ?><br />
        <?php echo $csv[0][32]; ?><br />
        eBay<br />
        <?php echo $csv[0][2]; ?><br />
        <?php echo $csv[0][0]; ?><br /> 
        <?php echo $csv[0][1]; ?><br />
    </td>

What I want to do is use a html page I have made for the template and echo the data from each order in a foreach loop. I would need to map out where on the page each element of sub-data goes (like in the example above) but have it cycle through each order generating a new page from my template (for each order) till it reaches the end. Hope this makes sense, please ask any questions that will help clarify what I’m trying to achieve if I’ve not made it clear enough.

Note: in the example array ive used the 1st order has 2 items and the 2 orders after that have 1 item each order, this is typical data, an order could have 1 or several items.

Comments

Comment posted by Glen Keybit

Perfect! thank you so much, it’s easy when you know how 🙂 I may have an issue on orders with multiple items to solve yet but this has certainly helped me move the idea along.

By