I haven't paste whole code as it will be quite a lot... .... I'm afraid even this is also too much .....
<?php
$frm_nm = "frm_bsc_cs"; // BSc - Computer Science.
print("<form name=$frm_nm action=\"mod.php\" method=post>");
print("<table name=outer width=100% callspacing=1 callpadding=1 border=1>");
print("<tr>");
print("<td width=50%>");
bld_tbl(tblSem1, 1, chk_sem1, hdn_sem1, $ruleSem1Min, $ruleSem1Max );
print("<td width=50%>");
bld_tbl(tblSem2, 2, chk_sem2, hdn_sem2, $ruleSem2Min, $ruleSem2Max );
print("</tr>");
...................... more code.............
printf("</table>");
print("</form>");
function bld_tbl($tblName, $semVal, $chbName, $hdn_sem_, $ruleMin, $ruleMax){
global $sess_prog;
global $link;
global $sess_part;
/ global $ruleSem1Min;
global $ruleSem1Max;
global $ruleSem2Min;
global $ruleSem2Max; /
$modStmt = "select mod_id, title, mod_wt from modid_titles_2002_2003 where prog = \"$sess_prog\" and part = \"$sess_part\" and semester = \"$semVal\" ";
$result = mysql_query($modStmt, $link);
// Check to see if you *did* get a result:
/ echo $tblName . ' ' . $semVal . ' ' . $chbName .' ' . $ruleMin . ' ' . $ruleMax . ' ' . $sess_prog . ' ' . $link . ' ' . $sess_part; /
/* echo " tblName : $tblName <p><br> ";
echo "semVal : $semVal <p><br>";
echo "chbName: $chbName <p><br>" ;
echo "ruleMin: $ruleMin <p><br>"; // not returned when run in NN
echo "ruleMax: $ruleMax <p><br>"; // not returned when run in NN
echo "sess_prog: $sess_prog <p><br>"; // not returned when run in NN
echo "link : $link <p><br>";
echo "sess_part: $sess_part <p><br>"; // not returned when run in NN
*/
if(!$result) {
echo 'Query: ' . $modStmt . ' failed.';
// No sense in continuing if the query failed:
return;
}
$num_row = mysql_num_rows($result);
if(!mysql_num_rows($result)) {
echo 'Query: ' . $modStmt . ' returned no rows.';
return;}
else{
// these are trackd for use in the mod.php file to run the for loop accroding to number of rows in each sem.
$hdnRowsSem = "hdnRowsSem_" . $semVal;
$hdnRowNum = mysql_num_rows($result);
}
print("<table name=$tblName width=100% cellspacing=\"2\" cellpadding=\"2\">");
print("<tr bgcolor=\"#FFDCB9\">");
print("<td colspan=4 align=center > ");
print("<b>Semester $semVal </b> (Select total modular weight between $ruleMin and $ruleMax.");
print("<input type=hidden name=$hdnRowsSem value=$hdnRowNum");
// print(" $hdnRowsSem and $hdnRowNum </td> </tr>");
print("<tr bgcolor=\"#FFDCB9\"> <th colspan=4 align=center > </th> </tr>") ;
print("<tr bgcolor=\"#FFCC99\" border=1> ");
print("<th> Module Code </th>");
print("<th> Module Name </th>");
print("<th> Weight </th>");
print("<th> Select $hdnRowsSem </th>");
print("</tr>");
for ($i=0; $i < $num_row ; $i++){
$row = mysql_fetch_array($result);
print("<tr>");
print("<td width=17%> $row[mod_id]");
$hdn_mod = ($hdn_sem_ . $i);
print("<input type=hidden name=$hdn_mod value=$row[mod_id] </td>");
print("<td> $row[title] </td>");
print("<td width=8%> $row[mod_wt] </td>");
$chk_name = $chbName. $i;
print("<td width=8%><input type=checkbox name=$chk_name onClick=\"fn_chk(this,$row[mod_wt],$semVal);\"></td>");
print("</tr>");
} // end of for loop
print("</table> </td>");
} / ------- end of funciton bld_tbl() ----- /
?>