PHP Drop Down Boxes always Isset -
hi have 2 drop down boxes used filter data mysql table, problem boxes show if set when use isset determin if of them have values selected.
here code drop boxes.
<?php if (isset($_post['referrer']) && $_post['referrer'] != "referrer") { $select = $_post['referrer']; } ?> <select name="referrer"> <option value="">referrer</option> <?php // records database (table "name_list"). $list=mysql_query("select distinct referrer masterip_details country_code='gb' , trim(ifnull(referrer,'')) <> '' order referrer desc"); // show records while loop. while($row_list=mysql_fetch_assoc($list)){ $referrer = $_post['referrer']; ?> <option value="<?php echo $row_list['referrer']; ?>" <?php if($row_list['referrer']==$select){ echo "selected"; } ?>><?php echo $row_list['referrer']; ?></option> <?php } ?> </select> <?php if (isset($_post['returning']) && $_post['returning'] != "returning") { $select2 = $_post['returning']; } ?> <select name="returning"> <option value="">referrer</option> <?php // records database (table "name_list"). $list2=mysql_query("select * repeater_drop_down order id desc"); // show records while loop. while($row_list2=mysql_fetch_assoc($list2)){ $returning = $_post['returning']; ?> <option value="<?php echo $row_list2['value']; ?>" <?php if($row_list2['value']==$select2){ echo "selected"; } ?>><?php echo $row_list2['title']; ?></option> <?php } ?> </select>
now here isset elements of code.
$returning = $_post['returning']; $referrer = $_post['referrer']; if (isset($returning, $referrer)){ //code // elseif (isset($returning)){ ///code // elseif (isset($referrer)){ //code // else { //code }
i haven't included queries work fine whether or not select both drop down boxes code automatically goes first isset both variable if 1 of boxes has option selected.
any advice or suggestions appreciated.
you should check value submitted form, not whether or not select post value set.
the value of referrer ''
(an empty string) if submitted without changing select. check instead.
Comments
Post a Comment