Nille Posted March 21, 2012 Share Posted March 21, 2012 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/259426-showing-subgroups-with-while-loop/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.