dongyanggan3025 2016-10-31 07:31
浏览 53
已采纳

使用PHP从SQL中获取navbar元素

I have a mySQL table containing stores. It looks like this:

id | name   | city
1  | H&M    | New York
2  | Gucci  | New York
3  | H&M    | Chicago
4  | H&M    | Boston
5  | Gucci  | Las Vegas
6  | Cavalli| New York
7  | H&M    | Phoenix

I have a drop-down menu that I want to be looking like this:

  • Home
  • Stores
    • New York
    • Chicago
    • Boston
    • Las Vegas
    • Phoenix

My question is: How do I fetch, without repeating, the cities I have stores in so I can make each of them a hyperlink in my drop-down menu like this: mypage.com/city/new-york. The page it will lead to, will obviously contain the stores where city='$_GET['city']'.

  • 写回答

1条回答 默认 最新

  • douhui1957 2016-10-31 07:40
    关注

    use DISTINCT this will help to optimize data MORE INFO

    Syntax:

    SELECT DISTINCT column FROM Table_name

    also you can use multiple columns

    Syntax:

    SELECT DISTINCT c1, c2, c3 FROM t1

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退
  • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?