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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.