Eiolon Posted December 2, 2011 Share Posted December 2, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/252273-jquery-collapseexpand-only-showing-first-row-from-database/ Share on other sites More sharing options...
joel24 Posted December 2, 2011 Share Posted December 2, 2011 thats because you are only calling the single next element with .session class... jQuery(this).children(".sessions").slideToggle(500); //or jQuery(this).nextAll(".sessions").slideToggle(500); Quote Link to comment https://forums.phpfreaks.com/topic/252273-jquery-collapseexpand-only-showing-first-row-from-database/#findComment-1293354 Share on other sites More sharing options...
Eiolon Posted December 2, 2011 Author Share Posted December 2, 2011 Thanks for your reply. When I use children, nothing expands. When I use nextAll it expands ALL the programs at once, not just the one I clicked on. Quote Link to comment https://forums.phpfreaks.com/topic/252273-jquery-collapseexpand-only-showing-first-row-from-database/#findComment-1293444 Share on other sites More sharing options...
Eiolon Posted December 2, 2011 Author Share Posted December 2, 2011 Nevermind, I solved it. Quote Link to comment https://forums.phpfreaks.com/topic/252273-jquery-collapseexpand-only-showing-first-row-from-database/#findComment-1293469 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.