Jump to content

empty value in dynalically generated pull-down menu


wkilc

Recommended Posts

I am dynamically bulilding a pull-down menu based on values from a table.

 

I think what's going on here, is when the "school" value is empty (no school is listed for some records) it shows an empty gap in the pull-down menu, with no value.

 

Is there a way to rectify this?  So far, I've just been inserting a "-" into the empty values in the table as a work around.

 

<? $result = @mysql_query("select distinct school from table ORDER BY school ASC");
if (mysql_num_rows($result) > 0) {
  print "<select>"; ?>
  <option <?php if(empty($_GET['school'])){ echo "selected=\"selected\""; } ?> value="<? echo "$page_name" ?>">DISPLAY ALL SCHOOLS</option>
  <? while ($row = mysql_fetch_array($result)) {
    print "<option ";
    if($_GET['school'] ==   $row['school']  ){ echo "selected=\"selected\""; }
    print " value=\"$page_name&start=0&school=" . $row['school'] . "\">" . $row['school'] . "</option>\n";
  }
  print "</select>";
} 
?> 

 

Thank you,

 

~Wayne

Link to comment
Share on other sites

try this

<?php $result = @mysql_query("select distinct school from table ORDER BY school ASC");
if (mysql_num_rows($result) > 0) {
  print "<select>"; ?>
  <option <?php if(empty($_GET['school'])){ echo "selected=\"selected\""; } ?> value="<? echo "$page_name" ?>">DISPLAY ALL SCHOOLS</option>
  <?php while ($row = mysql_fetch_array($result)) {
if(empty($row['school'])) continue; //added
    print "<option ";
    if($_GET['school'] ==   $row['school']  ){ echo "selected=\"selected\""; }
    print " value=\"$page_name&start=0&school=" . $row['school'] . "\">" . $row['school'] . "</option>\n";
  }
  print "</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.