Chevy Posted March 15, 2007 Share Posted March 15, 2007 Well I am making a PHP music player and I was wondering how would I skip to the next song if the song was NULL or it said "URL Of Song" I have tried this so far: $userstuff = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `username`='$user'")); if ($song == "song1"){ $next = "song2"; } if ($userstuff['song2'] == NULL || $userstuff['song2'] == "URL Of Song"){ $next = "song3"; } But that is not right logically Say I start at song1 and song2 is nothing, when I click Next Track I want it to go to song3, if song3 is nothing I want it to go to song4...all the way to ten, if you get what I mean. Link to comment https://forums.phpfreaks.com/topic/42774-complex-question/ Share on other sites More sharing options...
per1os Posted March 15, 2007 Share Posted March 15, 2007 A while loop would probably satisfy your request. $i=0; $x=true; while ((($userstuff[$i] == NULL || $userstuff[$i] == "URL Of Song") || ($x))) { // do song stuff here // if the song is good than exit by setting $x=false; // kill the loop after 10 tries. if ($i > 10) { $x=false; } $i++; //(very important) } Link to comment https://forums.phpfreaks.com/topic/42774-complex-question/#findComment-207615 Share on other sites More sharing options...
Chevy Posted March 15, 2007 Author Share Posted March 15, 2007 But wouldn't that just go through all the songs? I want it to stop when it finds a full one. EDIT: Ahh okay I will try that Link to comment https://forums.phpfreaks.com/topic/42774-complex-question/#findComment-207617 Share on other sites More sharing options...
Chevy Posted March 15, 2007 Author Share Posted March 15, 2007 It is still looping continesly on me.... $i=0; $x = true; while ((($userarray['song$i'] == NULL || $userarray['song$i'] == "URL Of Song") || ($x))) { $next = "song$i"; echo $next; $x=false; if ($i > 10) { $x=false; } $i++; //(very important) } Link to comment https://forums.phpfreaks.com/topic/42774-complex-question/#findComment-207625 Share on other sites More sharing options...
Chevy Posted March 15, 2007 Author Share Posted March 15, 2007 Anyone else want to take a shot at this? It is giving me a headache haha Link to comment https://forums.phpfreaks.com/topic/42774-complex-question/#findComment-207638 Share on other sites More sharing options...
boo_lolly Posted March 15, 2007 Share Posted March 15, 2007 i'd pull all the songs into an array, and use a switch statement. <?php /*get songs stored in database*/ $sql = "SELECT song_name FROM your_table"; $query = mysql_query($sql); /*pump matches into an array*/ while($row = mysql_fetch_array($query)){ $songArray[] = $row['song_name']; } /*set $_GET['song'] value*/ ((!isset($_GET['song'])) ? ($_GET['song'] = 0) : ("")); /*switch through songs*/ switch($_GET['song']){ case $_GET['song']: /*refresh the page to skip to next song if empty*/ if(empty($songArray[$_GET['song']])){ echo "<meta http-equiv=\"refresh\" content=\"0\"\;url=http://www.yoursite.com/?song=". $_GET['song']++ ."\">\n"; }else{ /*play $songArray[$_GET['song']];*/ } break; default: break; } ?> Link to comment https://forums.phpfreaks.com/topic/42774-complex-question/#findComment-207643 Share on other sites More sharing options...
Chevy Posted March 15, 2007 Author Share Posted March 15, 2007 Nah that would not work since the songs are not stored in a whole separate table, they are off site links. Link to comment https://forums.phpfreaks.com/topic/42774-complex-question/#findComment-207659 Share on other sites More sharing options...
Chevy Posted March 15, 2007 Author Share Posted March 15, 2007 $songs = array("song1", "song2", "song3", "song4", "song5", "song6", "song7", "song8", "song9", "song10"); foreach ($songs as $song){ if ($userarray[$song] != NULL && $userarray[$song] != "URL Of Song"){ echo $song; } } I think that is part of it, now I just need it to grab the first element of the array and the next I tried using current($song) and next($song) but they are not in the arrya form anymore :-/ this is really confusing to me. Link to comment https://forums.phpfreaks.com/topic/42774-complex-question/#findComment-207660 Share on other sites More sharing options...
boo_lolly Posted March 15, 2007 Share Posted March 15, 2007 you can apply the same logic to my code using either curl or shel_exec with the wget command Link to comment https://forums.phpfreaks.com/topic/42774-complex-question/#findComment-207662 Share on other sites More sharing options...
Chevy Posted March 15, 2007 Author Share Posted March 15, 2007 Hm. I guess I am not familiar with those at all...The code I posted last works fine echoing the songs that have a URL in them, but I want to know how I can get the first one and the next one. Link to comment https://forums.phpfreaks.com/topic/42774-complex-question/#findComment-207664 Share on other sites More sharing options...
boo_lolly Posted March 15, 2007 Share Posted March 15, 2007 Hm. I guess I am not familiar with those at all...The code I posted last works fine echoing the songs that have a URL in them, but I want to know how I can get the first one and the next one. there are many ways i'm sure. one way i've already shown you. Link to comment https://forums.phpfreaks.com/topic/42774-complex-question/#findComment-207680 Share on other sites More sharing options...
per1os Posted March 15, 2007 Share Posted March 15, 2007 <?php $songs = array("song1", "song2", "song3", "song4", "song5", "song6", "song7", "song8", "song9", "song10"); foreach ($songs as $key => $song){ if ($song != NULL && $song != "URL Of Song"){ echo $song; break; } } ?> Link to comment https://forums.phpfreaks.com/topic/42774-complex-question/#findComment-207695 Share on other sites More sharing options...
Chevy Posted March 15, 2007 Author Share Posted March 15, 2007 I am still having an EXTREAMLY hard time doing this... Starting to think it is impossible This is what I want it to do Display a link to go to the next song which if the current song was song1 then it would got to song2 unless it did not exist then it would got to song3 unless that didnt exist then it would go to song4, ect all the way to song10 and then die. Link to comment https://forums.phpfreaks.com/topic/42774-complex-question/#findComment-208336 Share on other sites More sharing options...
per1os Posted March 15, 2007 Share Posted March 15, 2007 <?php $currentSong = "song1"; $songs = array("song1", "URL Of Song", "song3", "song4", "song5", "song6", "song7", "song8", "song9", "song10"); $start = false; foreach ($songs as $key => $song){ if ($start) { if ($song != NULL && $song != "URL Of Song"){ echo '<a href=link.php?song=' . $song . '>Next Song</a>'; break; } } if ($song != $currentSong) { $start = true; } } ?> Is that what you want? Link to comment https://forums.phpfreaks.com/topic/42774-complex-question/#findComment-208341 Share on other sites More sharing options...
Chevy Posted March 15, 2007 Author Share Posted March 15, 2007 Yes, thank you! I thought it was possible xP Link to comment https://forums.phpfreaks.com/topic/42774-complex-question/#findComment-208345 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.