homepage Welcome to WebmasterWorld Guest from 54.211.73.232
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
MySQL identical fields
How can I get MySQL to discount identical fields?
yumigator

5+ Year Member



 
Msg#: 3663992 posted 3:21 am on Jun 1, 2008 (gmt 0)

My CMS is coming along, but I've run into a problem.

My system gives each item a unique id (auto_increment). Each item is also identified by its title. There may be more than one page in an item; in that case, each page gets its own row. As a result, there are some rows that have identical titles. The unique id is not used by my script and is merely there to ensure no two rows are identical.

I want now to be able to create a list of all my items, but the catch is I don't want items with multiple pages to be listed more than once. Only the first page in an item shall be displayed.

Is there any way with MySQL or PHP to filter the extra rows out such that when everything is processed, there is only one instance of each title in my list?

This is for the backened, so I'm not really concerned with the number of queries, but is there an efficient way to do this?

 

Pico_Train

5+ Year Member



 
Msg#: 3663992 posted 6:28 am on Jun 1, 2008 (gmt 0)

Select DISTINCT title from pages where title = $title ?

Jaunty Edward

5+ Year Member



 
Msg#: 3663992 posted 7:59 am on Jun 1, 2008 (gmt 0)

Select * from pages group by title order by id

that will show each title once and you can show the first or last item with the same title by using order by id desc or asc

Regards,
Jaunty

yumigator

5+ Year Member



 
Msg#: 3663992 posted 12:27 pm on Jun 1, 2008 (gmt 0)

Thanks, those both work well. I never could have found those on Google :D.

I ended up using the GROUP BY method, because after some searching I ran across COUNT(), which would even let me display how many pages were in each item.

Thanks again!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
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