|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 | ||||||
|
Member (6 bit)
Join Date: Sep 2002
Location: Scotland
Posts: 50
|
PHP and mySQL - stop duplicate values
Hi there,
I'm completely stuck on a duplicate values problem. I'm working with mySQL, PHP and Apache on my own PC. I can use it offline, for testing. What I'm trying to do in PHP is to print the directors' names in the same row in a HTML table as the dvd title. Instead, it prints the same dvd title with a different director, depending on how many directors made the movie. Some movies are directed by more than one director such as Fargo by the Coen brothers. Please ignore the data in the tables, as I know some of it is wrong e.g. spelling and year. I have a sample dvd mySQL database which breaks down into the following tables: dvd, details, director. The 'details' table has data on a dvd title: titleid (PK), title, year, region, subtitled. The 'director' table has data on a director: directorid (PK), forename, surname. The 'dvd' table holds data on from the above tables, it has foreign keys from 'details' and 'director' table : dvdid (PK), detailsid (FK), directorid(FK) Here's the data from 'details' Quote:
Quote:
Quote:
Quote:
Quote:
PHP Code:
To fix this duplicate value, I tried the 'GROUP BY' statement. PHP Code:
This works, to a point. It does print the dvd title once only BUT it left out the second director (Joel Coen) from the Fargo DVD title. e.g. Quote:
![]() Cheers, John Last edited by Jova; 01-11-2004 at 04:42 AM. |
||||||
|
|
|
|
|
#2 |
|
Staff
Premium Member
Join Date: Jul 1999
Location: Arlington, TN
Posts: 5,538
|
If a movie has two directors then you would need to use a sub-query to get the results properly. First select your DVD, then run a sub-query on those results. Something like:
"SELECT first query" while { "SELECT second query" { } //end second while } //end first while statement |
|
|
|
|
|
#3 |
|
Member (6 bit)
Join Date: Sep 2002
Location: Scotland
Posts: 50
|
Thanks, mairving.
I got it working now. I did need a second query. Now I can stop pulling my hair apart.
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|