PDA

View Full Version : Need Some Help With a Query.


noonespecial
09-02-2009, 10:21 PM
I have a mysql table with a bunch of band name - album names (for release dates):

Example: Paramore - Brand New Eyes

Now on a page I am grabbing all the results that match that particular band.

At the moment I am doing it like this:

title LIKE '%".$name."%'

However, this is searching through the entire word ... so if a band's name is in the album name for another artist ... it shows up incorrectly.

Is there anyway to fix this?

Dismounted
09-03-2009, 06:03 AM
Ideally, you should have an Artist field, and an Album field. This allows much more flexibility, such as the case you are seeing now.

To take it even further, there should be separate "artist" and "album" tables, as there can one artist to many albums (one-to-many relationship). In fact, you could potentially need a many-to-many relationship (more than one artist to an album). Doing this is called database normalisation.