Results 1 to 22 of 22
May 17, 2012, 22:32 #1
- Join Date
- Jan 2004
- Ohio, USA
- 0 Post(s)
- 0 Thread(s)
Display fields depending on whether one field is a duplicate of another
As many others do, I've Googled a lot & failed to find a passable answer. So I'm throwing myself at the mercy of the sitepoint.com gods, once again.
I have a table with 3 fields: id (primary/unique/auto increment), FirstName, LastName. I want to display, on a standard .php page, all records in the FirstName & LastName columns ONLY when the last name is unique. Let me show you an example:
| id | FirstName | LastName |
| 1 | Joe | Smith |
| 2 | Bob | Jones |
| 3 | Sam | Ross |
| 4 | Gene | Smith |
| 5 | Matt | Jones |
Crudely designed table aside, I think you get the idea.
Now: If a duplicate is found ANYWHERE in LastName, the first & last name for the first record with the unique LastName would appear on screen. All records with the duplicate LastName entries would be ignored. All other records that aren't affected ie have no duplicates would display as normal. In the above table, the names Joe Smith, Bob Jones, and Sam Ross would print (echo) to the screen. Gene Smith would be ignored since Smith had been used earlier, by Joe. The same, Matt Jones would be ignored since there is a Bob Jones. Sam Ross would print since Ross is only used one time, thus he fits the criteria.
With this piece of PHP code, the ultimate goal would be to make a list of people, with each surname being used only once.
Anyone know how? I found a lotta things that'd work with one non-id field but nothing that would work as I need.