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

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>";
} 
?> 

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.