Working on a simple enough page where there is a table listing some documents and if a tick box is ticked and the date entered into a text box beside it, the database is updated for each id of document to show the date
Relevant code is
echo "<form action='add_typed_documents.php' name=\"typing\"method=\"post\">\n";
echo "<table class=\"sample\"><tr><td>";
echo "Name</td><td>Audit Date</td><td>Auditor</td><td>Typist</td><td>Download Date</td><td>Typed Date</td><td>Select</td></tr>\n";
$showdoc = mysql_query("SELECT * FROM $prefix"."documents ORDER BY audit_date");
while ( $rowshowdoc = mysql_fetch_array($showdoc) ) {
echo "<tr>
<td>".$rowshowdoc ["description"]."</td>
<td>".$rowshowdoc ["audit_date"]."</td>
<td>".$rowshowdoc ["auditor"]."</td>
<td>".$rowshowdoc ["typist"]."</td>
<td>".$rowshowdoc ["download_date"]."</td>";
if ($rowshowdoc ["typed_date"] == "" && $typename == "typist" && $rowshowdoc ["typist"] == $_SESSION[nick] ){
echo "<td>".$rowshowdoc ["typed_date"]."<input type=\"checkbox\" value=".$rowshowdoc ["id"]." name=\"typed[]\"></td>";
echo "<td>".$rowshowdoc ["typed_date"]."<INPUT type=\"text\" name=\"date_typed_input[]\" value=\"$today\"></td>";
//echo "<td>".$rowshowdoc ["typist"]."<input type=\"checkbox\" value=".$rowshowdoc ["id"]." name=\"typing[]\"></td>";
//echo "<td>".$rowshowdoc ["download_date"]."<INPUT type=\"text\" name=\"date_downloaded_input[]\" value=\"$today\"></td>";
}
else{
echo "<td>".$rowshowdoc ["typed_date"]."</td>";
}
echo "</tr>";
}
echo '<tr><td><input type="submit" name="submit" value="Select" /></td></tr>' . "\n";
echo '</form>';
echo "</table><br></center>";
// check typing submitted values
if (isset($_POST['submit']))
{
$record= $_POST['typed'];
$dated= $_POST['date_typed_input'];
for($i=0; $i<count($record); $i++)
{
echo "<br>record[] = ".$record[$i]." _";
echo "<br>dated i = ".$dated[$i]." _";
$j = $i + 1;
echo "<br>dated j = ".$dated[$j]." _";
echo "you dated it ".$dated[$i]."<br />";
mysql_query("UPDATE $prefix"."documents set typed_date='$dated[$i]' WHERE id='$record[$i]'");
}
}
Critical bits in my mind are
echo "<form action='add_typed_documents.php' name=\"typing\"method=\"post\">\n";
echo "<td>".$rowshowdoc ["typed_date"]."<input type=\"checkbox\" value=".$rowshowdoc ["id"]." name=\"typed[]\"></td>";
echo "<td>".$rowshowdoc ["typed_date"]."<INPUT type=\"text\" name=\"date_typed_input[]\" value=\"$today\"></td>";
echo '<tr><td><input type="submit" name="submit" value="Select" /></td></tr>' . "\n";
if (isset($_POST['submit']))
The problem is that although the initial
$record= $_POST['typed'];
bit works and is an array of the various selected tick boxes as is displayed by
echo "<br>record[] = ".$record[$i]." _";
the secondary data in
$dated= $_POST['date_typed_input'];
doesn't seem to get poulated when viewed as
echo "<br>dated i = ".$dated[$i]." _";
the J variable can be ignored I was just checking to see if perhaps the array data started at 1 instead of zero.
weird thing is that sometimes this works but most often it doesn't
so is it wrong or is there another way of doing this. All I require is a table where users can select particular rows as theirs and enter individual dates for each document thus
docname 1 ----- tickbox----- fill_in_some_date_here
docname 2 ----- tickbox----- fill_in_some_date_here
docname 3 ----- tickbox----- fill_in_some_date_here
docname 4 ----- tickbox----- fill_in_some_date_here
And depending on which tickboxes they fill and the dates they enter it looks like this afterwards (assuming user 2 is using the page)
docname 1 ----- User 2------- 2006-07-21
docname 2 ----- tickbox------ fill_in_some_date_here
docname 3 ----- User 2------ 2006-07-22
docname 4 ----- tickbox------ fill_in_some_date_here
Any thoughts?
Thanks in advance
John