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
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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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