Forum Moderators: coopster
while($i<$num){
$users_id=mysql_result($result,$i,"members.MEMBER");
$Name=mysql_result($result,$i,"members.Name");
$adno=mysql_result($result,$i,"members.adno");
$comment=mysql_result($result,$i,reporting_prep.comment");
//explode the Name
$fullName = explode(".", $Name);
$firstname = $fullName[0];
$surname = $fullName[1];
echo"<tr><td>$firstname $surname</td><td> <input type=\"hidden\" name=\"adno".$i."\" value=\"$adno\" /><input type=\"hidden\" name=\"num\" value=\"$num\" /><textarea rows=\"5\" cols=\"100\" name=\"comment".$i."\">$comment</textarea>";
include"file2.php";
$i++;
}
<?php
$userid="test";
if(isset ($_POST['submit0'])){
$focus=$_POST['focus'];
$query0="DELETE FROM assessment_focus_lookup WHERE userid='$userid'";
mysql_query($query0);
for ($j=0; $j<count($_POST['focus']); $j++){
$focus = addslashes($_POST['focus'][$j]);
$query00="INSERT INTO assessment_focus_lookup (userid, af_id) VALUES ('$userid', '$focus')";
mysql_query($query00) or die (mysql_error());
}//end for loop
}
//get any data from db
$query000="SELECT * FROM assessment_focus_lookup WHERE userid='$userid'";
$result000=mysql_query($query000) or die (mysql_error());
while ($row = mysql_fetch_assoc($result000)) {
$checked[] = $row['af_id'];
}
/* get the checkbox labels */
$focus = get_checkbox_labels("assessment_focus_reading");
/* create the html code for a formatted set of
checkboxes */
$html_focus = make_checkbox_html($focus, 7, 800, "focus[]");
global $focus;
$table_name="assessment_focus_reading";
?>
<html>
<body>
<br>
<form name="focus" method="POST" action="<?php echo $PHP_SELF;?>">
<? echo "$html_focus"; ?>
<br>
<input type="submit" name="submit0" value="Submit">
</form>
</body>
</html>
<?php
function get_checkbox_labels($table_name) {
/* make an array */
$arr = array();
/* construct the query */
$query0 = "SELECT * FROM $table_name ORDER BY id DESC";
/* execute the query */
$qid = mysql_query($query0);
/* each row in the result set will be packaged as
an object and put in an array */
while($row= mysql_fetch_object($qid)) {
array_push($arr, $row);
}
return $arr;
}
/* Prints a nicely formatted table of checkbox choices.
$arr is an array of objects that contain the choices
$num0 is the number of elements wide we display in the table
$width is the value of the width parameter to the table tag
$name is the name of the checkbox array
$checked is an array of element names that should be checked
*/
function make_checkbox_html($arr, $num0, $width, $name, $checked) {
global $checked, $userid, $name, $width;
/* create string to hold out html */
$str = "";
/* make it */
$str .= "<table width=\"$width\" border=\"1\">\n";
$str .= "<tr valign=\"top\">\n";
/* determine if we will have to close add
a closing tr tag at the end of our table */
if (count($arr) % $num0 != 0) {
$closingTR = true;
}
$j = 1;
if (ISSET($checked)) {
/* if we passed in an array of the checkboxes we want
to be displayed as checked */
foreach ($arr as $ele) {
$str .= "<td width=\"14%\">";
$str .= "<b>$ele->name</b><br />";
$str .= "$ele->af
<input type=\"hidden\" name=\"userid\" value=\"$userid\">
<input type=\"checkbox\" name=\"$name\" value=\"$ele->name\"";
foreach ($checked as $key=>$value) {
if ($value == $ele->name) {
$str .= "checked=\"checked\"";
continue;
}
}
$str .= ">";
if ($j % $num0 == 0) {
$str .= "</tr>\n<tr valign=\"top\">";
} else {
$str .= "</td>\n";
}
$j++;
}
} else {
/* we just want to print the checkboxes. none will have checks */
foreach ($arr as $ele) {
$str .= "<td width=\"14%\">";
$str .= "<b>$ele->name</b><br />";
$str .= "$ele->af
<input type=\"hidden\" name=\"userid\" value=\"$userid\">
<input type=\"checkbox\" name=\"$name\" value=\"$ele->name\">";
if ($j % $num0 == 0) {
$str .= "</tr>\n<tr valign=\"top\">";
} else {
$str .= "</td>\n";
}
$j++;
}
}
/* tack on a closing tr tag if necessary */
if ($closingTR == true) {
$str .= "</tr></table>\n";
} else {
$str .= "</table>\n";
}
return $str;
}
?>