SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    If Empty Do Not Echo?

    Hi,

    I have a simple echo code which echoes everything in 3 rows. However it also echoes empty values. Can anyone advise how I can prevent the empty cells in the databsae from being echoed?

    So for example if one user only submits 1 skill and another user submits 3 skills. It will echo the 1 skills and 2 empty spaces and then the 3 skills from the second user.

    Code:
    <div class="eventskillsbox">
    				<?php
    $query = mysql_query("SELECT skill1, skill2, skill3
    FROM users ");	
    while($row = mysql_fetch_array($query)) {
    ?>
    <div class="eventskillscell">
    <?php echo $row['skill1']; ?>
    </div>
    <div class="eventskillscell">
    <?php echo $row['skill2']; ?>
    </div>
    <div class="eventskillscell">
    <?php echo $row['skill3']; ?>
    </div>
    
    <?php
    }
    ?>
    	</div>

  2. #2

  3. #3
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Thanks mate,

    I am trying to use that but it doesn't seem to be working. Do I simply change it to this?

    Code:
    <div class="eventskillsbox">
    				<?php
    $query = mysql_query("SELECT skill1, skill2, skill3
    FROM users ");	
    while($row = mysql_fetch_array($query)) {
    ?>
    <div class="eventskillscell">
    <?php echo (!empty($row['skill1'])) ? $row['skill1'] : ''; ?>
    </div>
    <div class="eventskillscell">
    <?php echo (!empty($row['skill2'])) ? $row['skill2'] : ''; ?>
    </div>
    <div class="eventskillscell">
    <?php echo (!empty($row['skill3'])) ? $row['skill3'] : ''; ?>
    </div>
    
    <?php
    }
    ?>
    	</div>

  4. #4
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,234
    Mentioned
    154 Post(s)
    Tagged
    0 Thread(s)
    That is one way, another would be:
    PHP Code:
    <div class="eventskillsbox">
                    <?php
    $query 
    mysql_query("SELECT skill1, skill2, skill3
    FROM users "
    );    
    while(
    $row mysql_fetch_array($query)) {
    ?>
    <?php 
    if (!empty($row['skill1'])) : ?>
    <div class="eventskillscell">
    <?php echo $row['skill1'] ; ?>
    </div>
    <?php endif; ?>
    <?php 
    if (!empty($row['skill2'])) : ?>
    <div class="eventskillscell">
    <?php echo $row['skill2'] ; ?>
    </div>
    <?php endif; ?>
    <?php 
    if (!empty($row['skill3'])) : ?>
    <div class="eventskillscell">
    <?php echo $row['skill3'] ; ?>
    </div>
    <?php endif; ?>

    <?php
    }
    ?>
        </div>

  5. #5
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Cheers matey, this one worked fine.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •