Yes, flying fingers late at night! So, here is a PHP page that lets you test the DJ code. It basically, let's you select a day and hour and pulls the DJ that would be working then. It displays some info just for testing.
It lets you test various days and hours and pulls the info from the shifts, getting the presenter.
Then, it pulls the info for that presenter and displays it. In real life, on the live site, it would be used to
display the DJ's picture from the djpicture name from the djimages folder and the djpromopicture, too.
(Most of this code would not be needed for the live site. Just the DB parts.) Here is the code for testing:
getpresenter.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Testing: Retrieve and display current presenter!</title>
</head>
<?php
include("my-connect.php");
// Locate the current DJ and retrieve their info...
$day = $_POST['day'];
$hour = $_POST['hour'] * 100;
$sql = "SELECT * FROM shifts WHERE days = '" . $day . "'";
echo "<center>Searching for DJ's using query = " . $sql . "</center>";
$result = mysql_query($sql, $dbConn) or die("Error in shifts query!<br>Error: " . mysql_error);
// First, calculate the start and end time of each shift to find the correct shift...
if(mysql_num_rows($result)==0){
echo "<br><br><center>No presenters scheduled today!<center><br><br>";
}else{
while($row = mysql_fetch_assoc($result)){
$dj = $row['presenter'];
$shift = explode(" to ", $row['hours']);
if( ($shift[0] >= $hour) && ($shift[1] <= $hour) )
break 2;
}
// The DJ's id is found, now retrieve their info...
$sql = "SELECT * FROM presenters WHERE id = '" . $dj . "'";
$result = mysql_query($sql, $dbConn) or die("Error in shifts query!<br>Error: " . mysql_error);
$row = mysql_fetch_assoc($result);
echo "<br><br><center>Current Presenter(DJ): " . $row['djname'] . ", Name of their picture: " . $row['djpicture'] . " and " . $row['djpromopicture']. "</center><br><br>";
$day="";
}
?>
<body>
<form name="test" action="getpresenter.php" method="post">
<center>
Select a day: <select id="day" name="day">
<option value="">Select Day</option>
<option value="Sunday">Sunday</option>
<option value="Monday">Monday</option>
<option value="Tuesday">Tuesday</option>
<option value="Wednesday">Wednesday</option>
<option value="Thursday">Thursday</option>
<option value="Friday">Friday</option>
<option value="Saturday">Saturday</option>
</select>
Select hour of day: <select name="hour" class="formFields" id="birth_year">
<option value="">Select a hour</option>
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
</select>
<input type="submit" name="test" value="Press to show presenter!"/>
</center>
</form>
</body>
</html>
On the live site, you would use the current date/time and use that in this way to display the picture:
<?php
include("my-connect.php");
// Locate the current DJ and retrieve their info...
$day = date('l'); //Lower-case L
$hour = date("G") * 100;
$sql = "SELECT * FROM shifts WHERE days = '" . $day . "'";
$result = mysql_query($sql, $dbConn) or die("Error in shifts query!<br>Error: " . mysql_error);
// First, calculate the start and end time of each shift to find the correct shift...
if(mysql_num_rows($result)==0){
echo "<br><br><center>No presenters scheduled at this timeslot!<center><br><br>";
}else{
while($row = mysql_fetch_assoc($result)){
$dj = $row['presenter'];
$shift = explode(" to ", $row['hours']);
if( ($shift[0] >= $hour) && ($shift[1] <= $hour) )
break 2;
}
// The DJ's id is found, now retrieve their info...
$sql = "SELECT * FROM presenters WHERE id = '" . $dj . "'";
$result = mysql_query($sql, $dbConn) or die("Error in shifts query!<br>Error: " . mysql_error);
$row = mysql_fetch_assoc($result);
// Display the DJ name and promo picture
echo "<center>Current Presenter(DJ): " . $row['djname'] . "</center><br>";
echo "<img src="djimages/" . $row['djpromopicture'] . ">";
}
?>
Well, hope that explains it...