Skip to main content
Participating Frequently
Mar 14, 2007 5:17 PM UTC
Answered

PHP/MySQL list sorting


I am working on a site that does reviews. On one of my pages I am needing to pull a list of my categories. However I only need one of each category. as you can see from the link below it currently is pulling everything from my category field including duplicates.

Is there a way that I can get this done. I am using DW8 to build my site. I am very green at php hand coding.

is this something that should be done in the SQL side or php?

http://www.dfwfoodguide.com/reviews2.php
This topic is closed to new replies. Start a new post to keep the conversation going.
Newsgroup_UserCorrect answer
Inspiring
Mar 14, 2007 5:22 PM UTC
newhorizonhosting.com wrote:
> is this something that should be done in the SQL side or php?

SQL.

SELECT * DISTINCT FROM categories

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/

8 replies

Inspiring
Mar 14, 2007 5:59 PM UTC
newhorizonhosting.com wrote:
> CANCEL THAT, I figured it out
>
> Thanks Million David

No probs.

> I may need to go out and by some more of your books to thank you

Ooh, yes please. ;-)

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Translate
Inspiring
Mar 14, 2007 5:49 PM UTC
Steve Fleischer wrote:
> I wouldn't have thought the categories table ought to have multiple
> entries of the same category...

You're right, but having looked at the output, I suspect that everything
is in one table. In other words, it ain't been normalized.

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Translate
Participating Frequently
Mar 14, 2007 5:47 PM UTC
CANCEL THAT, I figured it out

Thanks Million David, I may need to go out and by some more of your books to thank you
Translate
Inspiring
Mar 14, 2007 5:47 PM UTC
newhorizonhosting.com wrote:
> I get an error sayingMySQL erro #1604
> You have ab error in you SQL syntax near 'DISTINCT DROM' reviews' at line 1

It would help if you said what your table structure is like, but I
suspect that this is probably what you want:

SELECT DISTINCT category FROM reviews

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Translate
Participating Frequently
Mar 14, 2007 5:41 PM UTC
David -

When I use this stament and click test in DW

SELECT *
DISTINCT FROM categories

I get an error sayingMySQL erro #1604
You have ab error in you SQL syntax near 'DISTINCT DROM' reviews' at line 1
Translate
Inspiring
Mar 14, 2007 5:27 PM UTC
On Wed, 14 Mar 2007 17:22:39 +0000, David Powers <david@example.com>
wrote:

>SELECT * DISTINCT FROM categories

I wouldn't have thought the categories table ought to have multiple
entries of the same category...
--
Steve Fleischer
steve at flyingtigerwebdesign dot com
Hong Kong
Translate
Inspiring
Mar 14, 2007 5:26 PM UTC
On Wed, 14 Mar 2007 17:17:30 +0000 (UTC), "newhorizonhosting.com"
<charles@dieselinteractive.com> wrote:

> I am working on a site that does reviews. On one of my pages I am needing to
>pull a list of my categories. However I only need one of each category. as you
>can see from the link below it currently is pulling everything from my category
>field including duplicates.
>
> Is there a way that I can get this done. I am using DW8 to build my site. I am
>very green at php hand coding.
>
> is this something that should be done in the SQL side or php?
>
> http://www.dfwfoodguide.com/reviews2.php

Don't you have a category table with a list of all the categories? eg

1 Italian
2 Chinese
3 Mexican
4 Greek
etc etc

Then your restaurant table would include a field (say res_catid) in
which you entered the id of the category it was listed in. Makes it
easy to get a list of categories from the category table (there are no
duplicates in it) and also to list all restaurants where res_catid =
'2' etc.
--
Steve Fleischer
steve at flyingtigerwebdesign dot com
Hong Kong
Translate
Newsgroup_UserCorrect answer
Inspiring
Mar 14, 2007 5:22 PM UTC
newhorizonhosting.com wrote:
> is this something that should be done in the SQL side or php?

SQL.

SELECT * DISTINCT FROM categories

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Translate