Bear with me, I'm not the best at PHP, and I have to take over a project somebody else abandoned. They built a form where people choose one or more classes, and how many people they're enrolling.
Once the user picks a class and the number of enrollees, they press submit and go to registration page 2 where the totals are to be summed based on class costs and # of students. But the number of students isn't appearing for each class. Here's where I'm having trouble:
Page one does send the number of students for each class in an array that matches the class number. For example, if there were 4 classes available and the user selected class 213 - 1 student, and class 214 - 2 students, a print_r shows on page two:
Array ( [215] => [213] => 1 [212] => 2 [214] => )
But I'm not understanding how to generate that number when I print to the page:
here's what I've got, so far, on page two:
<?php
// several other variables were set here, dumped into db then...
// store all posted intemnos and descriptions in local arrays
$ids = $_POST['workshop_id'];
print_r($_POST['participantqty']);
// the above shows the arrays are sending and printing correctly: Array ( [215] => [213] => 1 [212] => 2 [214] => )
foreach ($_POST['workshop_id'] as $id){
$qty = $_POST['participatqty'][$id];
}
// is the above not how I do this? Does it go somewhere else
if(sizeof($_POST['workshop_id'])) {
// loop through array
$number = count($ids);
for ($i=0; $i<=$number; $i++)
{
// store a single item number and description in local variables
$itno = $ids[$i];
$qty_insert = $qty[$i];
print_r($qty_insert);
$query_insertItemWorkshop = "INSERT INTO tbl_registration_workshop (registration_id, workshop_id, regworkshop_qty) VALUES ('$reg_id', '$itno', '$qty_insert')";
$dberror = "";
$ret = mysql_query($query_insertItemWorkshop);
$query_selectAllItems_events = 'SELECT * FROM tbl_workshops where workshop_id = '.$itno;
@$result_all_events = mysql_query($query_selectAllItems_events);
@$numRows_all_events = mysql_num_rows($result_all_events);
@$num=mysql_num_rows($result_all_events);
@$z_row = mysql_fetch_array($result_all_events);
$qty_total=$qty_insert*$z_row['workshop_price'];
$total = $total + $qty_total;
if ($ids[$i] <> '') {
// below at qty_insert is where the number isn't generating
echo "<tr><td valign=top><b>Description:</b> ". $z_row['workshop_title'] ."</td><td align='right' colspan='2' width=300 valign=top>" . $qty_insert . " at ". $z_row['workshop_price'] ." each: </td><td valign=top> $". $qty_total ."</td></tr>";
}
}
}
?>