homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

Making sure a row does not display twice

5+ Year Member

Msg#: 4051606 posted 7:22 pm on Dec 30, 2009 (gmt 0)

I have a search query in which I link two tables, like so:
$query = "SELECT * FROM `venues`, `events` WHERE `venues`.`vid` = `events`.`venue` AND (`type` LIKE '%Concert%')"

This query is called when a user searches for a specific event type, like "Concert." It is supposed to return all venues that have events with "Concert" in their types array.

It works fine, but the problem is if a venue has two events with the "Concert" type, this query returns the venue twice. I tried adding a check within the mysql while loop to make sure a venue isn't displayed twice, but because this is outside of the query, it interferes with my pagination. (i.e., if it's set to display 3 results per page, it will sometimes only display 2 because it filters out the duplicated venues without changing the query).

So, is there anything I can add directly to the query in order to make sure that a venue is not displayed more than once?




WebmasterWorld Administrator lifeinasia us a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

Msg#: 4051606 posted 7:45 pm on Dec 30, 2009 (gmt 0)

Do you need to display anything from the events table? If not, just use "SELECT DISTINCT venues.*" instead of "SELECT *" in your query.


5+ Year Member

Msg#: 4051606 posted 7:51 pm on Dec 30, 2009 (gmt 0)

Perfect, thanks!

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved