Reputation: 665
I am creating a form for my workplace that will enter product serial numbers into a mySQL database.
You can see current working example here: http://jsfiddle.net/bELWq/
My issue at the moment is processing this form, at the moment I have a php script that simply echoes all of the information that is entered:
<?php
$supplier = $_POST['supplier'];
$date_inv = $_POST['date-inv'];
$date_rec = $_POST['date'];
$user = $_POST['user'];
$product = $_POST['product'];
$qty = $_POST['qty'];
$serial = $_POST['serial'];
foreach ($product as $p) {
echo "$p<br />";
}
foreach ($qty as $q) {
echo "$q<br />";
}
foreach ($serial as $s) {
echo "$s<br />";
}
echo $supplier;
echo $date_inv;
echo $user;
echo $date_rec;
?>
But the problem is that it echoes every product then all the qty's then all the serial numbers with nothing really to differentiate what belongs where.
Now i have racked my brain continuously over how to do this, and as i am not the most logically minded person it is starting to make my brain hurt.
Any suggestions on how to process this are greatly appreciated. Or if you can think of a better method to send the information, that would be good also.
Upvotes: 0
Views: 827
Reputation: 3335
You could add the data to a table like so.
<?
echo '<table>
<tr>
<th>Product</th>
<th>Quantity</th>
<th>Serials</th>
</tr>';
foreach ($product as $i => $p) {
$serial_cell = array();
foreach($serial[$i] as $si => $sv){
$serial_cell[] =$sv;
}
echo '
<tr>
<td>'.$product[$i].'</td>
<td>'.$qty[$i].'</td>
<td>'.implode('<br>',$serial_cell).'</td>
</tr>';
}
echo '
<tr>
<td>Supplier:</td>
<td colspan="2">'.$supplier.'</td>
</tr>
<tr>
<td>Invoice Date:</td>
<td colspan="2">'.$date_inv.'</td>
</tr>
<tr>
<td>User:</td>
<td colspan="2">'.$user.'</td>
</tr>
<tr>
<td>Date Received:</td>
<td colspan="2">'.$date_rec.'</td>
</tr>';
echo '</table>';
Upvotes: 1
Reputation: 11700
You could do something like this:
foreach ($serial as $key => $s) {
echo "$s<br />";
echo $serial[$key];
echo $qty[$key];
}
Upvotes: 1