I am trying to create unique playlist. regarding that my DB structure is...
aid (albumid) | sid (songid) | rid (artistid)
_________________|____________________|___________________
5001 | track-a | a
5002 | track-a | c
5001 | track-a | a:b
5001 | track-a | b
5001 | track-a | b:c
5001 | track-b | b
5001 | track-b | b:a
Its like this 5001 number album may have any number of song with name sid as track-1, but each time it is differentiated with unique artists like it is sung by artist a, b, c, if it sung by duet than I have differentiate it with :
that is these artist combination have also sung this. Now at time of insertion I wish to check combination if it already exist. My PHP code is
$track is array of track
$artist is array of artist (for artist combination array value may have ":", I have taken it as string.)
//SELECT QUERY FOR ALBUM
if (mysql_num_rows($sql) != 0) {
while ($row = mysql_fetch_assoc($sql)) {
$album_array[] = array( $row["sid"], $row["rid"]);
}
for ($z = 0; $z < count($track); $z++) {
if( in_array($track["z"],$album_array[0]) && empty(array_diff(explode(":",$album_array[1]), explode(":",$artist["z"]) )) ){
echo 'true';
} else {
echo 'false';
}
}
} else {
//SIMPLE INSERT CODE HERE
}
For combination
track-a | a
track-a | b
track-a | b:a
track-a | a:c
It should return me
-TRUE
-TRUE
-TRUE
-FALSE
but its returning me false each time. Please help me out.
$track["z"] and $artist["z"]
should be
$track[$z] and $artist[$z]
You are only checking against the first array $album_array[0]
. Is there only one returned?
Code page example: http://codepad.org/lE8eUBHY