Hey hey! It's GD Money. 🙂
Thanks as usual WP. OK, so I'm getting it broke down but am confused about the need for a seperate table for the song genres.
I have a table called "genres" that has each genre listed such as:
table genres
genid genre
1 Acoustic
2 Ambient
3 Alternative
and also a seperate table that has only the genres for each song:
table songgenre
songid gen1 gen2
1234 3 2
322 1 3
and additional tables that have info for the song such as:
table song
songid song_title bandid
1234 Yah Baby 23
322 Doo Wop 17
What I don't understand is why I wouldn't have the genids listed in table song. I don't see how having them in a seperate table would be reducing redundant info because either way it will be in a row with the same numbers. It seems like adding redundant info because of the additional songid being stored. I must not be doing it right or something.
How would this:
//////////////////
table songgenre
songid gen1 gen2
1234 3 2
322 1 3
table song
songid song_title bandid
1234 Yah Baby 23
322 Doo Wop 17
///////////////////////
be better than this:
//////////////////////
table song
songid song_title bandid gen1 gen2
1234 Yah Baby 23 3 2
322 Doo Wop 17 1 3
///////////////////////
The latter method is already a lot better than what I am currently doing since it is only storing tinyint instead of 20varchar, but I want to make sure I'm doing it the best way possible before I commit 100%. I'm happy to stick with Shrikes excellent advice and I'm certainly not doubting him but the way I'm doing it seems like overkill. Can anybody please help me see the light?
also,..I got everything laid out and setup my old query method first before I suped it up with my newly learned tricks. I think I can apply what Shrike has taught me to this query with the exception of the trickery in getting the genres from the genres table.
Old method with new tables:
$getInfo = "SELECT stitle, bandid FROM song WHERE songid = '$songid'";
$rs = mysql_query($getInfo, $conn) or die(mysql_error());
$row = mysql_fetch_assoc($rs);
$stitle = prepOut($row['stitle']);
$bandid = $row['bandid'];
$getInfo = "SELECT gen1, gen2 FROM songgenre WHERE songid = '$songid'";
$rs = mysql_query($getInfo, $conn) or die(mysql_error());
$row = mysql_fetch_assoc($rs);
$gen1 = $row['gen1'];
$gen2 = $row['gen2'];
$getInfo = "SELECT genre FROM genres WHERE genid = '$gen1' OR genid = '$gen2'";
$rs = mysql_query($getInfo, $conn) or die(mysql_error());
$row = mysql_fetch_assoc($rs);
$gen1 = $row['gen1'];
$gen2 = $row['gen2'];
$getInfo = "SELECT mp3, sdescr, lyrics, dlopt, vimage FROM songinfo WHERE songid = '$songid'";
$rs = mysql_query($getInfo, $conn) or die(mysql_error());
$row = mysql_fetch_assoc($rs);
$sdescr = prepOut($row['sdescr']);
$mp3 = prepOut($row['mp3']);
$vimage = $row['vimage'];
$lyrics = prepOut($row['lyrics']);
$dlopt = $row['dlopt'];
NEW METHOD ATTEMPT:
$getInfo = "SELECT song.stitle, song.bandid songgenre.gen1, songgenre.gen2, genre.genres songinfo.mp3, songinfo.sdescr, songinfo.lyrics, songinfo.dlopt, songinfo.vimage FROM song, songgenre, genres, songinfo WHERE song.songid = '$songid'"
AND songgenre.songid = song.songid
AND (
genres.genre = songgenre.gen1
OR genres.genre = songgenre.gen2
)
AND songinfo.songid=song.songid";
It's looking in the ballpark but the seperate songgenre table is throwing me off a bit. Any thoughts?