Outputting my PHP array into a page.

Associate
Joined
29 Dec 2004
Posts
2,253
Thanks to many of you guys (namely Sic and marc2003) i have been able to turn my static form which contained the same values over and over again into a lovely little array meaning i can just loop the form/validation etc as many times as i wish without having to copy/paste code.

Now what i need to do is take the array (which is now all working and validated properly) and output it to a phprtf file. Don't worry as i have done all the phprtf code (shown below), i just need to know how to take the bits out of my array and put them into the phprtf bit of code i have previously created.

Here's the code that i need the array to go into, which will be in a for loop (unless theres a better way)...the values in the array are item, quantity, reason, type, and asset, to replace $item1, $quantity1, $reason1 etc below.

Code:
// set item rows
$table->writeToCell(3, 1, '1.', $fonTopMain, $parCell);
$table->writeToCell(3, 2, $quantity1 . 'x ' . $item1, $fonTopMain, $parCell);
$table->writeToCell(3, 3, $asset1, $fonTopMain, $parCell);
$table->writeToCell(3, 4, $reason1, $fonTopMain, $parCell);
$table->writeToCell(3, 5, '[' . $type1 . ']', $fonTop, $parCell);
$table->writeToCell(3, 6, 'Status: [Authorised] ', $fonTop, $parCell);
$table->writeToCell(3, 6, '[Rejected]', $fonTopRed);
$table->writeToCell(3, 6, 'Initial:
Date:', $fonTop, $parCell);
$table->writeToCell(3, 6, '[Raise Purchase Order]', $fonTopRed, $parCell);
$table->writeToCell(3, 6, '[Use Existing Stock]', $fonTopBlue, $parCell);

Here is a typical output using print_r for the whole form:

Code:
Array ( [submit] => null [username] => [address] => Address 1 [lognumber] => [contactname] => [contactmail] => [theitem] => Array ( [0] => Brother HL-5240 [1] => Desktop PC and TFT ) [quantity] => Array ( [0] => 3 [1] => 1 ) [reason] => Array ( [0] => The old ones are broken. [1] => New person starting, needs a PC to work on. ) [thetype] => Array ( [0] => Array ( [0] => Replacement ) [1] => Array ( [0] => Enhancement ) ) [asset] => Array ( [0] => 089 [1] => ) [notes] => [Submit] => Submit ERF )

I know i need a loop etc but basically am not sure how to get the right bits out of the array. Any help hugely appreciated and promise once this is working im all sorted!

(fingers crossed)

Oh, and not sure if it's necessary but if you'd like to see the form (which outputs the arrays at the bottom of the page) it's here: http://www.richl.com/gpt/erf/erf_form.php.
 
Last edited:
Good lord i think i've done it. Does this look like an OK way to do it or is there a better way so i dont keep requesting POST data or something? Any comments welcome, id like to make it as efficient as possible!

Code:
	for($x = 0; $x < 1; $x++) {
$table->writeToCell(3, 1, '1.', $fonTopMain, $parCell);
$table->writeToCell(3, 2, $_POST['quantity'][$x] . 'x ' . $_POST['theitem'][$x], $fonTopMain, $parCell);
$table->writeToCell(3, 3, $_POST['asset'][$x], $fonTopMain, $parCell);
$table->writeToCell(3, 4, $_POST['reason'][$x], $fonTopMain, $parCell);
$table->writeToCell(3, 5, '[' . $_POST['thetype'][$x][0] . ']', $fonTop, $parCell);
$table->writeToCell(3, 6, 'Status: [Authorised] ', $fonTop, $parCell);
$table->writeToCell(3, 6, '[Rejected]', $fonTopRed);
$table->writeToCell(3, 6, 'Initial:
Date:', $fonTop, $parCell);
$table->writeToCell(3, 6, '[Raise Purchase Order]', $fonTopRed, $parCell);
$table->writeToCell(3, 6, '[Use Existing Stock]', $fonTopBlue, $parCell);
}
 
That "loop" is uneccessary, as it will only "loop" once. You might as well just do:
Code:
$table->writeToCell(3, 1, '1.', $fonTopMain, $parCell);
$table->writeToCell(3, 2, $_POST['quantity'][1] . 'x ' . $_POST['theitem'][1], $fonTopMain, $parCell);
$table->writeToCell(3, 3, $_POST['asset'][1], $fonTopMain, $parCell);
$table->writeToCell(3, 4, $_POST['reason'][1], $fonTopMain, $parCell);
$table->writeToCell(3, 5, '[' . $_POST['thetype'][1][0] . ']', $fonTop, $parCell);
$table->writeToCell(3, 6, 'Status: [Authorised] ', $fonTop, $parCell);
$table->writeToCell(3, 6, '[Rejected]', $fonTopRed);
$table->writeToCell(3, 6, 'Initial:
Date:', $fonTop, $parCell);
$table->writeToCell(3, 6, '[Raise Purchase Order]', $fonTopRed, $parCell);
$table->writeToCell(3, 6, '[Use Existing Stock]', $fonTopBlue, $parCell);
 
Haha yeah it's ok, i was just looping it once for testing it in various ways...am hoping to allow the user to specify how many time's its looped but thats this thread!

Have i done it the right way, does everything look ok with the code?
 
Back
Top Bottom