dongyanggan3025
dongyanggan3025
2016-10-31 07:31

使用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 douhui1957 5年前

    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

    点赞 评论 复制链接分享

相关推荐