donglu1973 2013-02-20 15:57 采纳率: 100%
浏览 37

填充选择列表正在创建重复/多个选项

I've got a database of states, cities, and listings. Within each city, I have multiple listings. For example:

FL => Miami => 10 listings

I am trying to populate a State drop-down menu with each State, however, my SQL query is pulling back ALL rows and creating multiple entries of States. In the example above, FL is appearing 10 times in the drop-down, because there are 10 records for it in the database.

But this doesn't look correct in the State drop-down menu. There should only be 1 FL. Hope someone can help!

Here is my query:

$squery = mysql_query("SELECT * FROM wp_postmeta WHERE wp_postmeta.post_id AND wp_postmeta.meta_key = 'state'");

Here is my 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 } ?>
  • 写回答

2条回答 默认 最新

  • doujin8476 2013-02-20 15:59
    关注

    Try select distinct * or select distinct meta_value rather than just select *.

    评论

报告相同问题?

悬赏问题

  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退