Yevgeniy Bagackiy Yevgeniy Bagackiy - 22 days ago 6
MySQL Question

How not to print empty string from database while editing record

I have a record in database where are two fields 'leader' and 'checker' are empty. I set it to

NULL
inside sql statement. Then when I want to edit record and press edit record button I got empty string as it is the name. here is the code:

<div class="projLeader">
<label>Captain:</label>
<ol>
<li class="placeholder" name="projLeader"><div class="adding">Drop Here</div></li>
<li class="dropClass" name="projLeader" <?php if (isset($projLeader)) echo 'value="'.$projLeader.'"' ?>><?php echo "<span class='closer'>x</span>".$projLeader.""?></li>
<input type="hidden" name="projLeader" class="hiddenListInput1" />
</ol>
</div>

<div class="projChecker">
<label>Coordinator:</label>
<ol>
<li class="placeholder" name="projChecker"><div class="adding">Drop Here</div></li>
<li class="dropClass" name="projChecker" <?php if (isset($projChecker)) echo 'value="'.$projChecker.'"' ?>><?php echo "<span class='closer'>x</span>".$projChecker."" ?></li>
<input type="hidden" name="projChecker" class="hiddenListInput2" />
</ol>
</div>


I want to print it only if there is name not just empty string. But even the fields are empty I got this How can I not to print empty fields?

Answer

You can use IF Else in Php block for Empty or Null value in variable which would set by select query result values. If variable is empty or null then it will not add the list item code. For ex-

<div class="projLeader">
<label>Captain:</label>
<ol>
    <li class="placeholder" name="projLeader"><div class="adding">Drop Here</div></li>  
<?php
if (($projLeader != "") && (!is_null($projLeader)) { ?>
    <li class="dropClass" name="projLeader"  <?php if (isset($projLeader)) echo 'value="'.$projLeader.'"' ?>><?php echo "<span class='closer'>x</span>".$projLeader.""?></li>
<?php } ?>  
    <input type="hidden" name="projLeader" class="hiddenListInput1" />
</ol>
</div>