Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unique_array?

Status
Not open for further replies.

yebaws

Technical User
Mar 22, 2007
42
GB
I have an SQL database that lists businesses details and includes a columns for location and business category.

Lets say, in "Townsville" there are 9 businesses - 4 hotels, 3 shops, 2 bars and no garages.

So hotel 1 will have column "business category" = hotel, "location" = townsville, "name" = hotel 1

and hotel 2 will have "business category" = hotel, "location" = townsville, "name" = hotel 2

etc., etc.

I want to make a page that will list all of the businesses in Townsville and their details - no problem so far by using a SELECT query for that location - but I also want to make a list of all of the business types / categories that are listed for that area, without duplicating them. So I want a page that will say at the top:

Townsville has the following businesses listed:

Hotels
Shops
Bars

...without duplicating the categories because there is more than one business in each category.

Seems like I should be able to do this with an array_unique command, but I can't seem to make it work - I think because I am not building an array first that the command can deal with ) I get an error "...the argument should be an array..."

Please can someone explain how I should use this command correctly, including how to select / build the array from the database correctly. Or is there another way to do it?

Thanks!





 
Well unique_array will only work on an array. If you are trying to do this on a mysql result pointer it won't work and it won't work in an sql query either.

You could get the info via the sql query by using GROUP by clause. I would guess that would be the best way to do what you are trying to do.

--
Tek-Tips Forums is Member Supported. Click Here to donate

<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.


 
That's just what I needed. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top