Sunday, 15 July 2012

php - Populating Select List is Creating Duplicate/Multiple Options -



php - Populating Select List is Creating Duplicate/Multiple Options -

i've got database of states, cities, , listings. within each city, have multiple listings. example:

fl => miami => 10 listings

i trying populate state drop-down menu each state, however, sql query pulling rows , creating multiple entries of states. in illustration above, fl appearing 10 times in drop-down, because there 10 records in database.

but doesn't right in state drop-down menu. there should 1 fl. hope can help!

here query:

$squery = mysql_query("select * wp_postmeta wp_postmeta.post_id , wp_postmeta.meta_key = 'state'");

here output:

<?php while($state_name = mysql_fetch_array($squery)) { ?> <option value="<?php if(isset( $state_name['meta_value'] )) { echo state_name['meta_value']; } ?>"> <?php if(isset( $state_name['meta_value'] )) { echo $state_name['meta_value']; }?> </option><?php } ?>

try select distinct * or select distinct meta_value rather select *.

php mysql sql wordpress drop-down-menu

No comments:

Post a Comment