0

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
  • SELECT DISTINCT city FROM ... Commented Oct 31, 2016 at 7:34

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Had not heard of this one. Worked great. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.