I am currently designing a script that will store song id's played into a session array. I don't want the songs to play again till the playlist has been played through. The songs must remain random though. What i have, sort of works, but sometimes it takes forever to find the next song so all i want to do now is select a song from the playlist where the id is not already in the array.
Here is what I have so far :
function get_song(){
include "dbconnection.php";
$played = $_SESSION['played'];
//$song_result = mysql_query("SELECT id, url, songname, bandname FROM radio ORDER BY RAND()");
$song_result = mysql_query("SELECT id, url, songname, bandname FROM radio WHERE id NOT IN ('".array($played)."') ORDER BY RAND()");
mysql_query("SELECT id, url, songname, bandname FROM radio ORDER BY RAND() LIMIT 1");
$file = mysql_fetch_object($song_result);
$howmany = mysql_num_rows($song_result);
mysql_close($db);
$beenplayed = sizeOf($played) - 1;
echo $beenplayed;
if($beenplayed >= $howmany){
$_SESSION['played'] = "";
}
if(in_array($file->id, $played)) $file = get_song();
return $file;
}
What I have for testing does not seem to be working because I am getting duplicate runs through the function. any help would be appreciated 🙂