Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

PHP/MySQL list sorting

Explorer ,
Mar 14, 2007 Mar 14, 2007

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
TOPICS
Server side applications
552
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Mar 14, 2007 Mar 14, 2007
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
LEGEND ,
Mar 14, 2007 Mar 14, 2007
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
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 14, 2007 Mar 14, 2007
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
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 14, 2007 Mar 14, 2007
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
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 14, 2007 Mar 14, 2007
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
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 14, 2007 Mar 14, 2007
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
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 14, 2007 Mar 14, 2007
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
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 14, 2007 Mar 14, 2007
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
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 14, 2007 Mar 14, 2007
LATEST
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
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines