Hello all,
Getting stuck on a semi-complex form in an application to track volunteers for my employer. In this portion of the script, the administrator is assigning X volunteers to a timeslot for a given job function. That means that I have to get three values into the database multiple times, with the final number not known.
I've been approaching this by setting each value as an array (lately going at it with a two-dimensional array) then trying to loop over the results with a SQL statement to insert. While there are many outstanding tutorials on how to handle multiple select fields, none that I've found deals with inserting multiple fields of information multiple times. Any ideas out there?
The values in question are sid, pid, and qty. Assign() will pass the values to Processassign() for processing.
My form code (which seems to be working well):
function assign()
{
-- excerpted code here --
echo'
<div class="leftmain">
<div class="headings">Shift Details</div>
<b>Position:</b><br>
'.$p['position_title'].'<br>
<br>
<b>Position Description:</b><br>
'.$p['position_desc'].'<br>
</div>
<div class="rightmain">
<div class="headings">Available Shifts</div>
<br>
<table class="rstyle">
<form name="editevent" method="GET" action=" ' . $_SERVER['SCRIPT_NAME'] . ' ">
<input type="hidden" name="mode" value="processassign" />
<input type="hidden" name="$arr[sid][]" value="'.$_GET['position_id'].'">
<input type="hidden" name="name" value="'.$_GET['name'].'">
<input type="hidden" name="$arr[pid][]" value="'.$_GET['position_id'].'">
';
$cur_date = "";
$shift = new pgsql(DBHOST,DB,DBUSER,DBPASS);
$shift->connect();
$sql="SELECT * FROM eventshifts WHERE event_id = '".$_GET['event_id']."' ORDER BY shift_starttime ASC;";
$shift->query($sql) or die("Could not execute query: ".$sql." - ".pg_last_error());
if ($shift->numRows() >=1){
//loop through results
for($i = 0; $i < $shift->numRows(); $i++){
$st = $shift->fetchObject($i);
$startdate = date("M j Y", strtotime($st->shift_starttime));
$starttime = date("g:i a", strtotime($st->shift_starttime));
$endtime = date("g:i a", strtotime($st->shift_endtime));
if ($cur_date != $startdate)
{
echo"
<tr><th colspan=2><b>$startdate</b></th>
<th>Qty.</th>
</tr>";
// now set the cur_* variables
$cur_date = $startdate;
}
// print the row data
echo'<tr>
<td align=right><b>'.$starttime.' - </b></td>
<td><b>'.$endtime.'</b></td>
<td><input type="text" name="$arr[qty][]" size="5"> </td>
</tr>';
}
} else {
echo'<tr><td colspan=2>No Shifts Created Yet.</td></tr>';
}
echo'
<tr>
<td colspan=2><input type="submit" value="Assign Shifts">
</tr>
</table>
</form>
</div>';
}
function processassign()
{
// Insert data from table above.
}