flemingmike Posted June 12, 2010 Share Posted June 12, 2010 hello, how can i take a result in seconds and turn it into minutes? i get the result from xml: $length = $tracks->track->length; Link to comment https://forums.phpfreaks.com/topic/204578-divide-result-by-60/ Share on other sites More sharing options...
mattal999 Posted June 12, 2010 Share Posted June 12, 2010 function decodeTime($seconds) { $mins = floor($seconds / 60); $secs = floor($seconds - ($mins * 60)); if(strlen($secs) == 1) $secs = "0".$secs; return $mins.":".$secs; } $length = decodeTime($tracks->track->length); OR if you just want a decimal: $length = $tracks->track->length / 60; Link to comment https://forums.phpfreaks.com/topic/204578-divide-result-by-60/#findComment-1071162 Share on other sites More sharing options...
flemingmike Posted June 12, 2010 Author Share Posted June 12, 2010 thanks, i would never haver figured that out. i had it with the /60, but thats ugly. i have an update button, is there any way i can update just the field that are from the xml file, or do i have to refresh the whole page? im more of a vb6 guy, and its much easier in there. here is my code: <?php include("style.php"); $hmm = simplexml_load_file('http://www.durhamit.ca:8181/1.0/?method=player.GetNowPlayingData'); foreach ($hmm->tracks as $tracks) { $artist = $tracks->track->artist; $title = $tracks->track->title; $album = $tracks->track->album; } function decodeTime($seconds) { $mins = floor($seconds / 60); $secs = floor($seconds - ($mins * 60)); if(strlen($secs) == 1) $secs = "0".$secs; return $mins.":".$secs; } $length = decodeTime($tracks->track->length); echo '<div id="musicinfo"> <table border="1" width="100%"> <tr> <td align="center"> <table border="0" width="455"> <tr> <td rowspan="4" width="100"> <img border="0" src="http://www.durhamit.ca:8181/1.0/?method=player.getNowPlayingPicture" width="100" height="100"></td> <td align="center" width="87"><b>Artist:</b></td> <td>'.$artist.'</td> <td rowspan="4" align="center" width="64"> <table border="0" width="47%" cellspacing="0" cellpadding="0"> <tr> <td align="center"><a href="parse.php"> <img border="0" src="images/Button-Refresh-icon.bmp" width="64" height="64"></a></td> </tr> <tr> <td align="center">Update</td> </tr> </table> </td> </tr> <tr> <td align="center" width="87"><b>Title:</b></td> <td>'.$title.'</td> </tr> <tr> <td align="center" width="87"><b>Album:</b></td> <td>'.$album.'</td> </tr> <tr> <td align="center" width="87"><b>Length:</b></td> <td>'.$length.'</td> </tr> </table> </td> </tr> <tr> <td align="center"> <table border="0" width="455"> <tr> <td align="center"> <a target="control" href="http://www.durhamit.ca:8181/1.0/?method=player.play"> <img border="0" src="images/Button-Play-icon.bmp" width="64" height="64"></a></td> <td align="center"> <a target="control" href="http://www.durhamit.ca:8181/1.0/?method=player.pause"> <img border="0" src="images/Button-Pause-icon.bmp" width="64" height="64"></a></td> <td align="center"> <a target="control" href="http://www.durhamit.ca:8181/1.0/?method=player.previous"> <img border="0" src="images/Button-Previous-icon.bmp" width="64" height="64"></a></td> <td align="center"> <a target="control" href="http://www.durhamit.ca:8181/1.0/?method=player.next"> <img border="0" src="images/Button-Next-icon.bmp" width="64" height="64"></a></td> </tr> <tr> <td align="center">Play</td> <td align="center">Pause</td> <td align="center">Previous</td> <td align="center">Next</td> </tr> <tr> <td align="center"> </td> <td align="center"> </td> <td align="center"> </td> <td align="center"> </td> </tr> <tr> <td align="center"> </td> <td align="center"> </td> <td align="center"> <iframe name="I1" width="1" height="1" scrolling="no" frameBorder="0"></iframe> </td> <td align="center"> </td> </tr> </table> </td> </tr> <tr> <td align="center"> </td> </tr> <tr> <td align="center"> </td> </tr> </table> </div>'; ?> Link to comment https://forums.phpfreaks.com/topic/204578-divide-result-by-60/#findComment-1071170 Share on other sites More sharing options...
mrMarcus Posted June 12, 2010 Share Posted June 12, 2010 <?php foreach ($hmm->tracks as $tracks) { $artist = $tracks->track->artist; $title = $tracks->track->title; $album = $tracks->track->album; } I'm not sure what you're doing with this here. You are looping through an entire array just to populate a variable with what will end up being the last entry in the array. Link to comment https://forums.phpfreaks.com/topic/204578-divide-result-by-60/#findComment-1071176 Share on other sites More sharing options...
flemingmike Posted June 12, 2010 Author Share Posted June 12, 2010 there is only a single entry from the array, so this is all i need/know how to do it. Link to comment https://forums.phpfreaks.com/topic/204578-divide-result-by-60/#findComment-1071184 Share on other sites More sharing options...
ignace Posted June 12, 2010 Share Posted June 12, 2010 function decodeTime($seconds) { $mins = floor($seconds / 60); $secs = floor($seconds - ($mins * 60)); if(strlen($secs) == 1) $secs = "0".$secs; return $mins.":".$secs; } $length = decodeTime($tracks->track->length); OR if you just want a decimal: $length = $tracks->track->length / 60; echo date('i', $seconds), ' Minutes'; Link to comment https://forums.phpfreaks.com/topic/204578-divide-result-by-60/#findComment-1071195 Share on other sites More sharing options...
mrMarcus Posted June 12, 2010 Share Posted June 12, 2010 there is only a single entry from the array, so this is all i need/know how to do it. <?php echo $hmm->tracks->track->album; //outputs American Idiot Link to comment https://forums.phpfreaks.com/topic/204578-divide-result-by-60/#findComment-1071242 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.