wkilc Posted August 20, 2010 Share Posted August 20, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/211333-empty-value-in-dynalically-generated-pull-down-menu/ Share on other sites More sharing options...
MadTechie Posted August 21, 2010 Share Posted August 21, 2010 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>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/211333-empty-value-in-dynalically-generated-pull-down-menu/#findComment-1101957 Share on other sites More sharing options...
wkilc Posted August 21, 2010 Author Share Posted August 21, 2010 PERFECT!!! Thank you. ~Wayne Quote Link to comment https://forums.phpfreaks.com/topic/211333-empty-value-in-dynalically-generated-pull-down-menu/#findComment-1102053 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.