Hi all, it's been awhile...
my prob. I have a form to order drinks in a bar, as below.
<div class="col_left">
<h2> Order Your Drinks And Food</h2><br />
<form action="process.php" method="post" name="orders">
<table border="1" class="trapezi">
<tr>
<th>Drink</th><th>Qty</th>
</tr>
<tr>
<td><input type="checkbox" name="drink[]" value="p/c">Carlsberg 50cl</td>
<td><input type="text" name="drinkno[]" size="2"></td>
</tr>
<tr>
<td><input type="checkbox" name="drink[]" value="c/half">Carlsberg 25cl</td>
<td><input type="text" name="drinkno[]" size="2"></td>
</tr>
<tr>
<td><input type="checkbox" name="drink[]" value="b/k">Keo Bottle</td>
<td><input type="text" name="drinkno[]" size="2"></td>
</tr>
<tr>
<td><input type="checkbox" name="drink[]" value="b/c">Carlsberg Bottle</td>
<td><input type="text" name="drinkno[]" size="2"></td>
</tr>
<tr>
<td><input type="checkbox" name="drink[]" value="b/w">Water 25cl</td>
<td><input type="text" name="drinkno[]" size="2"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="submit" value="Order"></td>
</tr>
</table>
</form>
</div>
the php script is so,
<?php
date_default_timezone_set('Asia/Nicosia');
$db=new sqlite3('daily.sqlite');
$name=htmlspecialchars($_COOKIE['visitor']);
$name=ucfirst($name);
$drink=$_POST['drink'];
$drinknum=$_POST['drinkno'];
$ordertime=date('H:i');
$date=date('dm');
$dord=(implode($_POST['drink']));
$drno=(implode($_POST['drinknum']));
//$db->exec("INSERT INTO lists (name,seat,drink,food,ticket,date)
// VALUES('$name','44','$dord','$ford','$ordertime','$date')");
echo "Drink order for ".$name."<br />";
foreach($drink as $dord) {
echo $dord."<br />";
}
echo $ordertime;
//etc;
?>
which works to a point, but what I need to do is work it so that when it is echo'd or added to the db the
drink and qty are a pair.
I tried array_combine, but if only one or two checkboxes are checked, it throws an error.
I tried array_pad to make the arrays the same length, but of course, thay only adds to the end of the array.
any help much appreciated.