kevstarlive
kevstarlive

Reputation: 260

Display categories from a database

I am currently updating my site. As you can see I currently have a list of catagories (example: Free Offers, Gifts, Accessories).

These catagories will then list to promotions and then link to a single page and each one of my promotion is saved in MySQL under my DBNAME xclocouk_mobile and table mobi and each one has a promo_cat as the field name with a category underneath it.

I know how to connect to this database. What I want to know is how do I get my index page to read and display a list of catagories found under the promo_cat as listed above?

I need them to list the title as shown on my page which is done manually. But I do not want it to display duplicates.

How can I accomplish this?

Upvotes: 0

Views: 87

Answers (2)

qsi
qsi

Reputation: 683

 $q = "SELECT promo_cat FROM mobi";
 $result = mysql_query($q,$connection);
 while($output = mysql_fetch_array($result)) {
    echo $output['category'];
 }

EDIT:

this will list duplicates if there are duplicates in your database, else it won't.

If you have duplicates in your db, use "select distinct(promo_cat) .. "

Upvotes: 1

aynber
aynber

Reputation: 23001

You want to use DISTINCT

SELECT DISTINCT(promo_cat) FROM xclocoauk.mobi

Upvotes: 0

Related Questions