Last active
May 14, 2024 00:16
-
-
Save JayGreentree/310bb1a03d80cbadafea3807a84bb47f to your computer and use it in GitHub Desktop.
php now playing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<title>Now Playing</title> | |
<style type="text/css" media="all">@import "./style.css";</style> | |
</head> | |
<body> | |
<div class="wrapper"> | |
<br /> | |
<?php | |
/* | |
v3.0 | |
NOW PLAYING PHP SCRIPT | |
Latest Update: July, 31 2018 | |
============================================================================= | |
EDIT BELOW | |
=============================================================================*/ | |
date_default_timezone_set('America/Chicago'); | |
$mysqli_server = "localhost"; | |
$mysqli_database = "radiodj"; | |
$mysqli_user = "db"; | |
$mysqli_pass = "db"; | |
$mysqli_port = "3306"; | |
$shufleUpcoming = True; // Don't show the correct order of upcoming tracks | |
$nextLimit = 1; // How many upcoming tracks to display? | |
$resLimit = 5; // How many history tracks to display? | |
/* | |
============================================================================= | |
END EDIT | |
=============================================================================*/ | |
function db_conn() { | |
global $opened_db, $mysqli_server, $mysqli_user, $mysqli_pass, $mysqli_database, $mysqli_port; | |
@$opened_db = mysqli_connect($mysqli_server, $mysqli_user, $mysqli_pass); | |
if (!$opened_db) { | |
echo "<p><strong>The database connection cannot be established! Please check if the login details are correct!</strong></p></div>"; | |
die(mysqli_error()); | |
} else { | |
@mysqli_select_db($opened_db, $mysqli_database) | |
or die(mysqli_error()); | |
} | |
} | |
function db_close($opened_db) {@mysqli_close($opened_db);} | |
function convertTime($seconds) { | |
$H = floor($seconds / 3600); | |
$i = ($seconds / 60) % 60; | |
$s = $seconds % 60; | |
return sprintf("%02d:%02d:%02d", $H, $i, $s); | |
} | |
?> | |
<table class="main_table" border="0" cellspacing="0" cellpadding="5"> | |
<?php | |
db_conn(); | |
$shuffleQuery = null; | |
If ($shufleUpcoming == True) { | |
$shuffleQuery = " ORDER BY RAND()"; | |
} | |
$nextquery = "SELECT songs.ID, songs.artist, queuelist.songID FROM songs, queuelist WHERE songs.song_type=0 AND songs.ID=queuelist.songID" . $shuffleQuery . " LIMIT 0," . $nextLimit; | |
$resultx = mysqli_query($opened_db, $nextquery); | |
if (!$resultx) { | |
echo mysqli_error(); | |
exit; | |
} | |
if (mysqli_num_rows($resultx) > 0) { | |
// If there tracks in the playlist, we show them | |
$inc = 0; | |
echo " <tr>" . "\n"; | |
echo " <td class=\"header_live\">SOON ON RADIODJ</td>\n"; | |
echo " </tr>" . "\n"; | |
echo " <tr>" . "\n"; | |
echo " <td>"; | |
while($rowx = mysqli_fetch_array($resultx)) { | |
echo htmlspecialchars($rowx['artist'], ENT_QUOTES); | |
//if the current track is not the last, we put a separator | |
if ($inc < (mysqli_num_rows($resultx) -1)) { | |
echo ", "; | |
} | |
$inc += 1; | |
} | |
echo "</td>" . "\n"; | |
echo " </tr>" . "\n"; | |
} | |
//Uncomment this if you would like to show a message when no track is prepared. | |
else { | |
echo " <tr>" . "\n"; | |
echo " <td class=\"header_live\">SOON ON RADIODJ</td>\n"; | |
echo " </tr>" . "\n"; | |
echo " <tr>" . "\n"; | |
echo " <td>Sorry Nothing scheduled at this time</td>\n"; | |
echo " </tr>" . "\n"; | |
} | |
// ======================== // | |
$query = "SELECT `ID`, `date_played`, `artist`, `title`, `duration` FROM `history` WHERE `song_type` = 0 ORDER BY `date_played` DESC LIMIT 0," . ($resLimit+1); | |
$result = mysqli_query($opened_db, $query); | |
if (!$result) { | |
echo mysqli_error(); | |
exit; | |
} | |
if (mysqli_num_rows($result) == 0) { | |
exit; | |
} | |
$inc = 0; | |
while($row = mysqli_fetch_assoc($result)) { | |
if ($inc == 0) { | |
echo " <tr>" . "\n"; | |
echo " <td class=\"header_live\">NOW PLAYING</td>\n"; | |
echo " </tr>" . "\n"; | |
echo " <tr>" . "\n"; | |
echo " <td class=\"playing_track\"><strong>" . htmlspecialchars($row['artist'], ENT_QUOTES) . " - " . htmlspecialchars($row['title'], ENT_QUOTES) . " [" . convertTime($row['duration']) . "]</strong></td>\n"; | |
echo " </tr>" . "\n"; | |
if ($resLimit > 0) { | |
echo " <tr>" . "\n"; | |
echo " <td class=\"header_live\">RECENTLY PLAYED SONGS</td>\n"; | |
echo " </tr>" . "\n"; | |
} | |
} else { | |
if ($resLimit > 0) { | |
echo " <tr>" . "\n"; | |
echo " <td>" . date('H:i:s', strtotime($row['date_played'])) . " - " . htmlspecialchars($row['artist'], ENT_QUOTES) . " - " . htmlspecialchars($row['title'], ENT_QUOTES) . " [" . convertTime($row['duration']) . "]</td>\n"; | |
echo " </tr>" . "\n"; | |
} | |
} | |
$inc += 1; | |
} | |
@mysqli_free_result($opened_db, $result); | |
db_close($opened_db); | |
?> | |
</table> | |
<br /> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment