Jump to content

[SOLVED] skipping empty values


rugzo

Recommended Posts

Hi all,

 

i have a query in my select option, it queries the x column in the database and builds the select list. But my problem is that it is also showing empty columns. How can i modify my query so it only shows the columns with values and skipps the empty ones?

 

Thanks...

 

<select class="input" name="project" >

<option value=""><?=$row->project?></option>

<?php $ara = "SELECT * FROM listings ORDER BY project"  ;

      $cak = mysql_query($ara);

while ($don = mysql_fetch_array($cak))

{

 

  ?>

<option value="<?php echo $don[project] ; ?>" ><?php echo $don[project] ; ?>"</option>

        <?php

}

?>

</select>

Link to comment
https://forums.phpfreaks.com/topic/156403-solved-skipping-empty-values/
Share on other sites

Without knowing your table structure, this should work.

 

<select class="input" name="project" >
<option value=""><?=$row->project?></option>
<?php 
$ara = "SELECT * FROM listings ORDER BY project" ;
$cak = mysql_query($ara);
while ($don = mysql_fetch_array($cak))
{
    if($don['project'])
        echo "<option value=\"". $don['project'] ."\"> ". $don['project'] ."</option>"; 
} 
?>
</select>

 

Also this

<select class="input" name="project" >
<option value=""><?=$row->project?></option>
<?php 
$ara = "SELECT * FROM listings WHERE project != "" ORDER BY project" ;
$cak = mysql_query($ara);
while ($don = mysql_fetch_array($cak))
{
    echo "<option value=\"". $don['project'] ."\"> ". $don['project'] ."</option>"; 
} 
?>
</select>

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.