Jump to content

Showing subgroups with while loop


Nille

Recommended Posts

I'm trying to list all titles from one table, and then list subgroup titles from a subgroup table. I only want to list the subgroups if the user have selected "Group4". Now the while loop is only listing the first subgroup title, and not the next ones.

the first while loops keeps on looping after Group4, so this seems to work fine.

 

And the Group4 title is showing two times, and I would like it to only show one time.

 

I'm using a JavaScript to show the subgroups.

<script type="text/javascript">

function vis (it, box) {

var vis = (box.checked) ? "block" : "none";

document.getElementById(it).style.display = vis;

}

</script>

 

 

<?php

 

 

$query = mysql_query("SELECT groupID, Title FROM Group");

while ($row = mysql_fetch_array($query)) {

if($row[Title] == "Group4"){

?>

<input type="checkbox" id="group" value= "<?$row[groupID]?>" name="group[]" onclick="vis('div1', this) "/><label for="<?$row[groupID]?>"><? echo $row[title]?></label> <br/>

<?php

$query2 = mysql_query("SELECT gID, title FROM subgroup");

while ($row2 = mysql_fetch_array($query2)) {

?>

<div class="rad" id="div1" style="display:none">

  <input type="checkbox" id="group" value="<?$row2[groupID]?>" name= "group[]"  ><label for="<?$row2[title]?>"><? echo $row2[title]?></label> <br/>

</div>

<?php

}

}

 

?>

<input type="checkbox" id="group" value="<?$row[groupID]?>" name= "group[]"  ><label for="<?$row[title]?>"><? echo $row[title]?></label> <br/>

<?php

}

?>

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/259426-showing-subgroups-with-while-loop/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.