genista Posted July 20, 2014 Share Posted July 20, 2014 (edited) All, I am taking the output for every title in my Database and displaying it in a box. Within that box I am providing the opportunity to open another box with further content inside. The problem with the code below is that when you click on the expand button it expands in all the boxes, not just the one you are clicking in. I don't understand why this is happening when everything else is ok - any fixes and explanations are greatly appreciated: // GOING THROUGH THE DATA if($result->num_rows > 0) { //echo "<hr />"; while($fetch=mysqli_fetch_array($result)) { $title=$fetch['title']; $feed_rss=$fetch['url']; $content_id=$fetch['content_id']; $source_image=$fetch['source_image']; $item_id = $fetch['item_id']; $item_title = $fetch['item_title']; $item_date = $fetch['fetch_date']; $item_description = $fetch['item_description']; $item_url = $fetch['item_url']; ///////////////////////////////////////////////////////////////////////////////// // ?> <div class="box col5"> <?php $query_string = "cid={$content_id}&t={$item_id}&item_title={$item_title}"; $url_query_string = "http://www.disciply.com/article/index.php?" . $query_string; /*Start of dynamic content open*/ echo "<p>$title</p>"; echo "<img src=$source_image />"; echo "<p>item_url = $item_url</p>"; ?> <div class="panel_button" style="display: visible;"><img src="../images/expand.png" alt="expand"/> <a href="#"><?php echo $item_title; ?></a></div> <div class="panel_button" id="hide_button" style="display: none;"><img src="../images/collapse.png" alt="collapse" /> <a href="#">Hide</a> <object type="text/html" data='<?php echo $item_url;?>' width="100%" height="800px" style="overflow:auto;border:5px ridge blue"> </object> </div> </div> Edited July 20, 2014 by genista Quote Link to comment https://forums.phpfreaks.com/topic/290001-problem-with-div-in-loop/ Share on other sites More sharing options...
Ch0cu3r Posted July 20, 2014 Share Posted July 20, 2014 Your problem is nothing to do with PHP. You are most likely using JavaScript to toggle your panels visibility. You need to alter your JavaScript do so it only changes the visibility for the panel you have click on, example - http://jsfiddle.net/STnRc/ Quote Link to comment https://forums.phpfreaks.com/topic/290001-problem-with-div-in-loop/#findComment-1485739 Share on other sites More sharing options...
genista Posted July 21, 2014 Author Share Posted July 21, 2014 Thanks, and you are right. Looking at your fiddle it seems I need to increment a value for each panel button within each box in php to have this work individually rather than for all boxes? G Quote Link to comment https://forums.phpfreaks.com/topic/290001-problem-with-div-in-loop/#findComment-1485841 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.