wigglesby Posted November 25, 2009 Share Posted November 25, 2009 Hi I have the following code: <?php $limit = 4; for ($i=1; $i<= $limit ;$i++) { $file = call_user_func(array($profs, 'getFile'.$i)); $filedesc = call_user_func(array($profs, 'getFileDesc'.$i)); if(empty($file)){ echo ' '; } else{ echo '<div class="box info">'; echo '<h2>pdf downloads</h2>'; echo '<ul class="attached_files">'; $img = image_tag('pdf.jpg', array('height'=>'30', 'width'=>'30')); $filedesc = ( $filedesc !== '' ) ? $filedesc : 'Download File'; echo "<li><a href=\"/preview/sports_professionals/{$file}\">{$img}</a><br />{$filedesc}<br /></li>"; echo '</ul>'; echo '</div>'; } } ?> It loops through and if $file is empty, does not display the <div id="box info"> The only problem is, If I have 2 files (getFile1 and getFile2) that are called, it displays 2 divs, one with file1 and the other with file2. I just want to display both file in the same <div id="box info"> Thanks [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/182898-hide-a-div-if-empty/ Share on other sites More sharing options...
taquitosensei Posted November 25, 2009 Share Posted November 25, 2009 put your loop inside the div echo '<div class="box info">'; echo '<h2>pdf downloads</h2>'; echo '<ul class="attached_files">'; $limit = 4; for ($i=1; $i<= $limit ;$i++) { $file = call_user_func(array($profs, 'getFile'.$i)); $filedesc = call_user_func(array($profs, 'getFileDesc'.$i)); if(empty($file)){ echo ' '; } else{ $img = image_tag('pdf.jpg', array('height'=>'30', 'width'=>'30')); $filedesc = ( $filedesc !== '' ) ? $filedesc : 'Download File'; echo "<li><a href=\"/preview/sports_professionals/{$file}\">{$img}</a><br />{$filedesc}<br /></li>"; } echo '</ul>'; echo '</div>'; Link to comment https://forums.phpfreaks.com/topic/182898-hide-a-div-if-empty/#findComment-965380 Share on other sites More sharing options...
wigglesby Posted November 25, 2009 Author Share Posted November 25, 2009 That still displays the div I want the div NOT to display if there are no files. hope this makes sense? Thanks Link to comment https://forums.phpfreaks.com/topic/182898-hide-a-div-if-empty/#findComment-965414 Share on other sites More sharing options...
wigglesby Posted November 25, 2009 Author Share Posted November 25, 2009 What I mean is, the code provided above, displays the div by default as it is being echo'd out before the loop. So the div will display even if there are no files. I want it so, the div is displayed only if there are files. Thank you Link to comment https://forums.phpfreaks.com/topic/182898-hide-a-div-if-empty/#findComment-965419 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.