PDA

View Full Version : Check box problem



Neelima
08-04-2010, 08:38 AM
Hi ,

I have a problem with check box. can any body help me.
here if i select the class the sections are selecting but when i submit i need to display class and sections separate. i am able to display classes but when i want to display sections i am facing the problem. plz help me on this.....

Below is my code.....



<?php
mysql_pconnect("localhost","root","");
mysql_select_db("zftutorial");
if($_POST['submit']){
extract($_POST);
echo "<pre>";
echo "<BR>";
print_r($class);
}
?>
<script type="text/javascript">
function checkall(idv,ids)
{ //alert(idv);
var a=new Array();
a=document.getElementsByName(ids);
for(var i=0;i<a.length; i++){ //alert("hi");
a[i].checked=document.getElementById(idv).checked;
}
}
</script>
<form action="" method="post" name="frm">
<table cellpadding="0" cellspacing="5" border="0">
<?php
$sql=mysql_query("select * from m_classes order by class_id");
while($row=mysql_fetch_array($sql)){
?>
<tr><td><strong><input type="checkbox" id="<?php echo $row['class_name'];?>" name="class[]" onclick="checkall('<?php echo $row['class_name'];?>','<?php echo $row['class_name'];?>[]')" value="<?php echo $row['class_id'];?>"/><?php echo $row['class_name'];?></strong>
<table>
<?php
$sql2=mysql_query("select * from m_classes_sections where class_id='".$row['class_id']."'");
while($row2=mysql_fetch_array($sql2)){
?>
<tr><td><input type="checkbox" name="<?php echo $row['class_name'];?>[]" value="<?php echo $row['class_id'].','.$row2['section_id'];?>"/><?php echo $row2['section_name'];?></td></tr>
<?php } ?>

</table>
</td></tr>
<?php }?>
<tr><td><input type="submit" name="submit" value="submit" /></td></tr>
</table>
</form>