Jump to content

Hide a div if empty


wigglesby

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

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