rugzo Posted May 1, 2009 Share Posted May 1, 2009 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> Quote Link to comment Share on other sites More sharing options...
Prismatic Posted May 1, 2009 Share Posted May 1, 2009 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> Quote Link to comment Share on other sites More sharing options...
rugzo Posted May 1, 2009 Author Share Posted May 1, 2009 Thanks, the first one solved it Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.