Jump to content

jQuery collapse/expand only showing first row from database


Eiolon

Recommended Posts

I have a table that has the first row being the name of a program, and the second row being the session(s) available.  The program and sessions are being pulled from a database.

 

Example:

 

=======================================
English 101          Date / Time
=======================================
Session A             9/1/2012
Session B             10/1/2012
=======================================
Math 101             Date / Time
=======================================
Session A             9/1/2012
Session B             10/1/2012

 

When the program name such as "English 101" is clicked, the row with the sessions expand so you can see what is available.

 

However, the jQuery is only displaying the first session "Session A".

 

I know my database query is correct, as if I remove the jQuery the table is displayed properly in full.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function() {
  jQuery(".sessions").hide();
  jQuery(".programs").click(function()
  {
    jQuery(this).next(".sessions").slideToggle(500);
  });
});
</script>
</head>

<table>
<?php 
$last = '0';
do {
if($row_programs['pid'] != $last){ 
?>
<tr class="programs">
<th align=left><?php echo $row_programs['pname']; ?></th>
<th align=left>Date / Time</th>
</tr>
<?php } ?>
<tr class="sessions">
<td><?php echo $row_programs['sname']; ?></td>
<td><?php echo $row_programs['date_time']; ?></td>
</tr>
<?php 
$last = $row_programs['pid']; 
}  while ($row_programs = mysql_fetch_assoc($programs));
?> 
</table>


</body>

</html>

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.