0

Here i am populating my dropdowns with database fields using php my code follows,

while ($row = mysql_fetch_array($result)) {
$series1 .= "<option id='Series1' value='" . $row['Series'] ."'>" . $row['Series'] ."             </option>";
}

after fetching i echo it to html

<select id="Series1"  onchange="changeVal('Series1')">
    <option value="">Please select</option>
        <?php echo $series1 ?>
</select>

my problem is i have some null values in the database field, i don't want that to be inserted in the options field. my final result now look like this preview

please help me.

3
  • Share your SQL Query, that could help us determine what is going wrong... Commented May 17, 2013 at 6:26
  • 2
    add WHERE col IS NOT NULL in the where clause Commented May 17, 2013 at 6:26
  • Yup, JW nailed it in fact, don't even need to see the SQL :-) Commented May 17, 2013 at 6:27

3 Answers 3

4

Try this

while ($row = mysql_fetch_array($result)) {
   if($row['Series'] != '' || $row['Series'] != NULL) {
       $series1 .= "<option id='Series1' value='" . $row['Series'] ."'>" . $row['Series'] ."             </option>";
   }
}

OR

In your sql query

SELECT * FROM your_table WHERE Series IS NOT NULL
Sign up to request clarification or add additional context in comments.

Comments

2

You can try like this

  while ($row = mysql_fetch_array($result)) {
  if(isset($row['Series'])) {
   $series1 .= "<option id='Series1' value='" . $row['Series'] ."'>" . $row['Series'] ."             </option>";
        }
      }

Comments

1

Try this...

<select id="Series1"  onchange="changeVal('Series1')">
    <option value="">Please select</option>


    <?php
while ($row = mysql_fetch_array($result)) 
{
    if($row['Series'] != '' || $row['Series'] != NULL) 
     {
?>
      <option value="<?php echo $row['Series']; ?>"><?php echo $row['Series']; ?></option>  
</select>



<?php
     }
}
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.