Author Topic: need help with radio script  (Read 1376 times)

djclewes

  • Regular Member
  • **
  • Posts: 47
  • Karma: 0
    • View Profile
Re: need help with radio script
« Reply #30 on: May 11, 2012, 09:14:06 AM »
i take it i just delete this in getdj.php

      <tr>
       <td align="right">DJs Show Promo Picture:</td>
        <td align="left"><input type="file" id="djpromopicture" name="djpromopicture" size="35" /></td>
      </tr>


to delete the promo line.

and to add 1400 - 1700

               <option  value="1400 to 1600">1400 to 1600</option>
               <option  value="1400 to 1700">1400 to 1700</option>
                    <option  value="1700 to 1800">1600 to 1800</option>

ErnieAlex

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 1847
  • Karma: 32
    • View Profile
Re: need help with radio script
« Reply #31 on: May 11, 2012, 12:56:31 PM »
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
PHP Code: [Select]

<!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>TestingRetrieve 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 Code: [Select]

<?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... 

djclewes

  • Regular Member
  • **
  • Posts: 47
  • Karma: 0
    • View Profile
Re: need help with radio script
« Reply #32 on: May 11, 2012, 01:27:16 PM »
i am getting this code in getpresenter.php

Searching for DJ's using query = SELECT * FROM shifts WHERE days = 'Friday'


Current Presenter(DJ): Martan Lawrence, Name of their picture: martan.png and


so i take it thats working ok but the png does not show

djclewes

  • Regular Member
  • **
  • Posts: 47
  • Karma: 0
    • View Profile
Re: need help with radio script
« Reply #33 on: May 11, 2012, 01:34:41 PM »
when adding it to my website i get this code

{\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 Courier New;}} {\*\generator Msftedit 5.41.21.2509;}\viewkind4\uc1\pard\lang2057\f0\fs22\par Error: " . mysql_error);\par // First, calculate the start and end time of each shift to find the correct shift...\par if(mysql_num_rows($result)==0)\{\par echo "

No presenters scheduled at this timeslot!


";\par \}else\{\par while($row = mysql_fetch_assoc($result))\{\par $dj = $row['presenter'];\par $shift = explode(" to ", $row['hours']);\par \tab if( ($shift[0] >= $hour) && ($shift[1] <= $hour) )\par \tab\tab break 2;\par \tab \}\par // The DJ's id is found, now retrieve their info...\par $sql = "SELECT * FROM presenters WHERE id = '" . $dj . "'";\par $result = mysql_query($sql, $dbConn) or die("Error in shifts query!
Error: " . mysql_error);\par $row = mysql_fetch_assoc($result);\par // Display the DJ name and promo picture\par echo "
Current Presenter(DJ): " . $row['djname'] . "

";\par echo "";\par \}\par ?>\par }


also do i need to change this code to uk timezone

djclewes

  • Regular Member
  • **
  • Posts: 47
  • Karma: 0
    • View Profile
Re: need help with radio script
« Reply #34 on: May 11, 2012, 01:42:50 PM »
this is what it looks like on my site


ErnieAlex

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 1847
  • Karma: 32
    • View Profile
Re: need help with radio script
« Reply #35 on: May 11, 2012, 01:55:56 PM »
Yes, it is working.  It was just a sampler to show that you can use day/hour to pull the pictures and DJ info.

Use the last code to actually show the picture...  Hey, actually, I will alter that getpresenter code to show
the pix for you...   Here it is:

PHP Code: [Select]

<!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>TestingRetrieve 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="";
  }
  echo 
"<br><img src='djimages/" $row['djpicture'] . "'>";
  echo 
"<img src='djimages/" $row['djpromopicture'] . "'><br>";
?>
<body>
<form name="test" action="../Dee/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>


This new version just shows the images...   I also noticed there is an extra "(" in the djadminupdate.php file.
In the line that updates data, remove the ) just before the WHERE.   Hope that helps...

djclewes

  • Regular Member
  • **
  • Posts: 47
  • Karma: 0
    • View Profile
Re: need help with radio script
« Reply #36 on: May 11, 2012, 02:07:09 PM »
any idea what this link is about

 /Dee/getpresenter.php

ErnieAlex

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 1847
  • Karma: 32
    • View Profile
Re: need help with radio script
« Reply #37 on: May 11, 2012, 02:31:01 PM »
Sorry, that was my stupid editor redoing links.  Remove the ../Dee/ part...  Sorry!

And, this is the code you need to use to pull the data from the database and images based on NOW's day/hour:

PHP Code: [Select]

<?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 
"<center><img src="djimages/" . $row['djpromopicture'] . "></center>";
      // display PROMO picture, or change to djpicture, whichever you want...
  }
?>


Sorry, helping too many people today...

djclewes

  • Regular Member
  • **
  • Posts: 47
  • Karma: 0
    • View Profile
Re: need help with radio script
« Reply #38 on: May 11, 2012, 02:38:42 PM »
Errors in shift update/insert!
Query=INSERT INTO shifts (presenter, days, hours) VALUES (Enter new DJ NAME..., 'Monday', '0900 to 1200')
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'new DJ NAME..., 'Monday', '0900 to 1200')' at line 1


any idea on why thats appeared and i am still unsure on how to add it to my website :(

djclewes

  • Regular Member
  • **
  • Posts: 47
  • Karma: 0
    • View Profile
Re: need help with radio script
« Reply #39 on: May 11, 2012, 02:41:14 PM »
i get this error also when saved in a .htm

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!
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 "

No presenters scheduled at this timeslot!


"; }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!
Error: " . mysql_error); $row = mysql_fetch_assoc($result); // Display the DJ name and promo picture echo "
Current Presenter(DJ): " . $row['djname'] . "

"; echo ""; }

ErnieAlex

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 1847
  • Karma: 32
    • View Profile
Re: need help with radio script
« Reply #40 on: May 11, 2012, 02:44:04 PM »
Okay, this part of the error:  VALUES (Enter new DJ NAME..., 'M

  shows that you are inserting a new DJ, but, you didn't enter a name for the DJ.  It was still the default!

  I didn't give you a user manual...  LOL...    First, you create a DJ and fill in all the data and select two pixes
one for the DJ and one for the site's promo display.  Then, press UPDATE.  After that, you can select that
new Dj and add or remove scheduled shifts.   Did that make sense?  Hope so...

djclewes

  • Regular Member
  • **
  • Posts: 47
  • Karma: 0
    • View Profile
Re: need help with radio script
« Reply #41 on: May 11, 2012, 02:57:48 PM »
i have setup a presenter up for now but when go on getpresenter.php   i get No presenters scheduled today!

but if i insert the time and day manualy my presenter shows up is there something i need to change for it to match gmt time zone ?

ErnieAlex

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 1847
  • Karma: 32
    • View Profile
Re: need help with radio script
« Reply #42 on: May 11, 2012, 03:36:46 PM »
Yes, I am sorry, too many programming chores going on... 

Use this line before using and date functions:

   date_default_timezone_set('Europe/London');

That should work for you!


djclewes

  • Regular Member
  • **
  • Posts: 47
  • Karma: 0
    • View Profile
Re: need help with radio script
« Reply #43 on: May 11, 2012, 03:53:42 PM »
have i done this correct cause still not displaying the picture

PHP Code: [Select]
<!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>TestingRetrieve and display current presenter!</title>
</
head>
<?
php
  
include("my-connect.php");
date_default_timezone_set('Europe/London');
  
  
// 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="";
  }
  echo 
"<br><img src='djimages/" $row['djpicture'] . "'>";
  echo 
"<img src='djimages/" $row['djpromopicture'] . "'><br>";
?>
<body>
<form name="test" action="http://lcradio.co.uk/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>
</

djclewes

  • Regular Member
  • **
  • Posts: 47
  • Karma: 0
    • View Profile
Re: need help with radio script
« Reply #44 on: May 11, 2012, 04:25:48 PM »
will this display the djs automatically change on the website once i finally work out how
to get the picture on the site