Hi can anyone tell me what is wrong with my script that i have used from other posts on this forum please?
<?php //set timezone putenv ('GMT=Europe/London'); mktime(0,0,0,1,1,2012); $wday = date("0"); $time = date("Hi"); if ($day == 7) // Sunday { switch($time) { case ($time >= '0000' && $time <= '0600'): echo""; break; case ($time >= '0600' && $time <= '0900'): echo""; break; case ($time >= '0900' && $time <= '1200'): echo""; break; case ($time >= '1200' && $time <= '1400'): echo""; break; case ($time >= '1400' && $time <= '1600'): echo""; break; case ($time >= '1600' && $time <= '1800'): echo""; break; case ($time >= '1800' && $time <= '2000'): echo""; break; case ($time >= '2000' && $time <= '2100'): echo""; break; case ($time >= '2100' && $time <= '2200'): echo""; break; case ($time >= '2200' && $time <= '2400'): echo""; break; default: echo""; break; } } elseif($day == 2) { echo""; } else { switch($time) { case ($time >= '0000' && $time <= '0600'): echo""; break; case ($time >= '0600' && $time <= '0900'): echo""; break; case ($time >= '0900' && $time <= '1200'): echo""; break; case ($time >= '1200' && $time <= '1400'): echo""; break; case ($time >= '1400' && $time <= '1700'): echo""; break; case ($time >= '1700' && $time <= '1800'): echo""; break; case ($time >= '1800' && $time <= '2000'): echo""; break; case ($time >= '2000' && $time <= '2100'): echo""; break; case ($time >= '2100' && $time <= '2200'): echo""; break; case ($time >= '2200' && $time <= '2400'): echo""; break; } } elseif($day == 3) { echo""; } else { switch($time) { case ($time >= '0000' && $time <= '0600'): echo""; break; case ($time >= '0600' && $time <= '0900'): echo""; break; case ($time >= '0900' && $time <= '1200'): echo""; break; case ($time >= '1200' && $time <= '1400'): echo""; break; case ($time >= '1400' && $time <= '1600'): echo""; break; case ($time >= '1700' && $time <= '1800'): echo""; break; case ($time >= '1800' && $time <= '2000'): echo""; break; case ($time >= '2000' && $time <= '2200'): echo""; break; case ($time >= '2200' && $time <= '2400'): echo""; break; } } elseif($day == 4) { echo""; } else { switch($time) { case ($time >= '0000' && $time <= '0600'): echo""; break; case ($time >= '0600' && $time <= '0900'): echo""; break; case ($time >= '0900' && $time <= '1200'): echo""; break; case ($time >= '1200' && $time <= '1400'): echo""; break; case ($time >= '1400' && $time <= '1700'): echo""; break; case ($time >= '1700' && $time <= '1800'): echo""; break; case ($time >= '1800' && $time <= '2000'): echo""; break; case ($time >= '2000' && $time <= '2100'): echo""; break; case ($time >= '2100' && $time <= '2200'): echo""; break; case ($time >= '2200' && $time <= '2400'): echo""; break; } } elseif($day == 5) { echo""; } else { switch($time) { case ($time >= '0000' && $time <= '0600'): echo""; break; case ($time >= '0600' && $time <= '0900'): echo""; break; case ($time >= '0900' && $time <= '1200'): echo""; break; case ($time >= '1200' && $time <= '1400'): echo""; break; case ($time >= '1400' && $time <= '1600'): echo""; break; case ($time >= '1700' && $time <= '1800'): echo""; break; case ($time >= '1800' && $time <= '2000'): echo""; break; case ($time >= '2000' && $time <= '2200'): echo""; break; case ($time >= '2200' && $time <= '2400'): echo""; break; } } elseif($day == 6) { echo""; } else { switch($time) { case ($time >= '0000' && $time <= '0600'): echo""; break; case ($time >= '0600' && $time <= '0800'): echo""; break; case ($time >= '0800' && $time <= '1000'): echo""; break; case ($time >= '1000' && $time <= '1300'): echo""; break; case ($time >= '1300' && $time <= '1700'): echo""; break; case ($time >= '1700' && $time <= '1900'): echo""; break; case ($time >= '1900' && $time <= '2200'): echo""; break; case ($time >= '2200' && $time <= '2400'): echo""; break; } } elseif($day == 0) { echo""; } else { switch($time) { case ($time >= '0000' && $time <= '0600'): echo""; break; case ($time >= '0600' && $time <= '0800'): echo""; break; case ($time >= '0800' && $time <= '1000'): echo""; break; case ($time >= '1000' && $time <= '1200'): echo""; break; case ($time >= '1200' && $time <= '1400'): echo""; break; case ($time >= '1400' && $time <= '1600'): echo""; break; case ($time >= '1600' && $time <= '1800'): echo""; break; case ($time >= '1800' && $time <= '2000'): echo""; break; case ($time >= '2000' && $time <= '2200'): echo""; break; case ($time >= '2200' && $time <= '2400'): echo""; break; } } ?>DJ, please put code inside the PHP tags next time. It makes it much easier for us to copy to our editors.
This code is in good condition. What is the problem with it. Have you put it on a site?
Here are a few comments on it. First, if you have a database to go with your project, dump this code and we will help you create a better version in just a few lines… There seems to be a few logic issues with this type of code.
It would be hard to edit, unless this version is always staying in this form. Well, I am reposting it with a few changes in the formatting so I can read it better…
Okay, I only got part of it reformatted to be readable and it is a mess with the logic. You have days separated, but, most of them do one line and the have an else after the if has already closed. They echo an image if the day matches and then have an else that will run for all the other days… You will get the wrong day displayed because it doesn’t go thru all the days first. ? ? ? So, that is not correct. Tell us what you are trying to do with this code and we can help you…
[php]
<?php //set timezone putenv ('GMT=Europe/London'); mktime(0,0,0,1,1,2012); $wday = date("0"); $time = date("Hi"); if ($day == 7) // Sunday { switch($time) { case ($time >= '0000' && $time <= '0600'): echo""; break; case ($time >= '0600' && $time <= '0900'): echo""; break; case ($time >= '0900' && $time <= '1200'): echo""; break; case ($time >= '1200' && $time <= '1400'): echo""; break; case ($time >= '1400' && $time <= '1600'): echo""; break; case ($time >= '1600' && $time <= '1800'): echo""; break; case ($time >= '1800' && $time <= '2000'): echo""; break; case ($time >= '2000' && $time <= '2100'): echo""; break; case ($time >= '2100' && $time <= '2200'): echo""; break; case ($time >= '2200' && $time <= '2400'): echo""; break; default: echo""; break; } } elseif($day == 2) { // Tuesday echo""; } else { switch($time) { case ($time >= '0000' && $time <= '0600'): echo""; break; case ($time >= '0600' && $time <= '0900'): echo""; break; case ($time >= '0900' && $time <= '1200'): echo""; break; case ($time >= '1200' && $time <= '1400'): echo""; break; case ($time >= '1400' && $time <= '1700'): echo""; break; case ($time >= '1700' && $time <= '1800'): echo""; break; case ($time >= '1800' && $time <= '2000'): echo""; break; case ($time >= '2000' && $time <= '2100'): echo""; break; case ($time >= '2100' && $time <= '2200'): echo""; break; case ($time >= '2200' && $time <= '2400'): echo""; break; } } elseif($day == 3) { //Wednesday echo""; } else { switch($time) { case ($time >= '0000' && $time <= '0600'): echo""; break; case ($time >= '0600' && $time <= '0900'): echo""; break; case ($time >= '0900' && $time <= '1200'): echo""; break; case ($time >= '1200' && $time <= '1400'): echo""; break; case ($time >= '1400' && $time <= '1600'): echo""; break; case ($time >= '1700' && $time <= '1800'): echo""; break; case ($time >= '1800' && $time <= '2000'): echo""; break; case ($time >= '2000' && $time <= '2200'): echo""; break; case ($time >= '2200' && $time <= '2400'): echo""; break; } } elseif($day == 4) { echo""; } else { switch($time) { case ($time >= '0000' && $time <= '0600'): echo""; break; case ($time >= '0600' && $time <= '0900'): echo""; break; case ($time >= '0900' && $time <= '1200'): echo""; break; case ($time >= '1200' && $time <= '1400'): echo""; break; case ($time >= '1400' && $time <= '1700'): echo""; break; case ($time >= '1700' && $time <= '1800'): echo""; break; case ($time >= '1800' && $time <= '2000'): echo""; break; case ($time >= '2000' && $time <= '2100'): echo""; break; case ($time >= '2100' && $time <= '2200'): echo""; break; case ($time >= '2200' && $time <= '2400'): echo""; break; } } elseif($day == 5) { echo""; } else { switch($time) { case ($time >= '0000' && $time <= '0600'): echo""; break; case ($time >= '0600' && $time <= '0900'): echo""; break; case ($time >= '0900' && $time <= '1200'): echo""; break; case ($time >= '1200' && $time <= '1400'): echo""; break; case ($time >= '1400' && $time <= '1600'): echo""; break; case ($time >= '1700' && $time <= '1800'): echo""; break; case ($time >= '1800' && $time <= '2000'): echo""; break; case ($time >= '2000' && $time <= '2200'): echo""; break; case ($time >= '2200' && $time <= '2400'): echo""; break; } } elseif($day == 6) { echo""; } else { switch($time) { case ($time >= '0000' && $time <= '0600'): echo""; break; case ($time >= '0600' && $time <= '0800'): echo""; break; case ($time >= '0800' && $time <= '1000'): echo""; break; case ($time >= '1000' && $time <= '1300'): echo""; break; case ($time >= '1300' && $time <= '1700'): echo""; break; case ($time >= '1700' && $time <= '1900'): echo""; break; case ($time >= '1900' && $time <= '2200'): echo""; break; case ($time >= '2200' && $time <= '2400'): echo""; break; } } elseif($day == 0) { echo""; } else { switch($time) { case ($time >= '0000' && $time <= '0600'): echo""; break; case ($time >= '0600' && $time <= '0800'): echo""; break; case ($time >= '0800' && $time <= '1000'): echo""; break; case ($time >= '1000' && $time <= '1200'): echo""; break; case ($time >= '1200' && $time <= '1400'): echo""; break; case ($time >= '1400' && $time <= '1600'): echo""; break; case ($time >= '1600' && $time <= '1800'): echo""; break; case ($time >= '1800' && $time <= '2000'): echo""; break; case ($time >= '2000' && $time <= '2200'): echo""; break; case ($time >= '2200' && $time <= '2400'): echo""; break; } } ?>[/php]
i want a on air now feature like http://www.bbc.co.uk/radio1/ with the name of the presenter and the picture of the presenter. with different presenters for different shows
Okay, that should be easy…
First, do you have MySQL on your site? Can we use that?
Also, will the DJ’s change much or are they locked in? I mean, do you want a simple ADMIN for this, too?
Why I ask these question, is that this would be soooo very simple with SQL and PHP…
Let me know, I have time tonight free and might be able to help you…
First, do you have MySQL on your site? yes
Also, will the DJ’s change much or are they locked in? I mean, do you want a simple ADMIN for this, too? yes it would be brilliant.
i just want it to look like the bbc radio 1 banner with the presenter picture above the menu bar saying on air now (name)
Great! Something like this is actually simple. I have to leave for a few hours. I will drum up a sample for you later or maybe tonight. It will be so very simple using queries instead of all those crazy IF clauses…
Check back in a few hours later on… And, thanks for the answers…
can not wait to see the results
I just got home… I need a couple hours… Too many things to do… Check back later!
ok its 4am in the uk but i will wait
Sorry, it’s (now) 11 PM here in the states! SORRY, forgot where you might be!
I am working on it now. Just have to get some of the database queries fixed up…
Perhaps a night’s sleep might do well for you… LOL…
I will need another 30 minutes or more!
no i am wide a wake i am looking forward to the results
Can not wait to see this
i have started to design my idea and here is how id like it to look
Okay, the first thing we discussed was the displaying of the DJ’s when they are online.
You called them “presenters” … So, to do that section of your site, you would need to create a database system to display them, but, also, an ADMIN section to handle changes. Here is a tutorial on how to do this.
I will show the code a little later on after you absorb this information…
DJ Presenter’s Tutorial
So, to handle DJ’s data using a MySQL database, it is basically very easy. First, you have to design the data you might need in this project.
First, you would need a list of DJ’s or “presenters” as you called them. There are several items you would need in this type of database.
I reviewed the website and the code you currently had in place and came up with these items. Here is a list and descriptions:
ITEM DESCRIPTION MySQL Field Name
DJ-Index ( Database index auto-incremented ) ID
DJ-Name ( Actual reall name of the DJ ) djname
DJ-NickName ( On-Air name that the DJ goes by ) djnickname
DJ-Description ( Descripton for use in AD's, etc ) djdesc
DJ-Picture ( Picture of DJ for use on site ) djpicture
DJ-Show-Picture ( On-site promo picture for show ) djshowpicture
DJ-Days-Online ( Days of week online/onsite ) djdays
DJ-Hours-Online ( Hours or Shift online/onsite ) djhours
DJ-Last-Updated ( TimeStamp for last updated ) djlastupdated
Now, the above will have to be created so you can populate it with the actual data. After reviewing the above table, I decided it should be
two tables to make it easier to program. Therefore, These are the two tables you will need to create in MySQL…
TABLE1: presenters
FIELDS: ID (auto-increment)
djname (text)
djnickname (text)
djdesc (text)
djpicture (text)
djshowpicture (text)
TABLE2: shifts
FIELDS: ID (auto-increment)
presenter (INT)
day (text)
hours (text)
The first table is used to keep tract of all of the presenters. This is just a list of each DJ with thier info.
What is nice is that a simple report can be created from this list. It can show all of the DJ’s and could even
include all of the sifts for each DJ. (In just a few lines of PHP code!)
The second table is interesting. It actally will contain a list of all shifts for all DJ’s. If a DJ has more than
one shift, it would be listed one after the other. So, let’s say DJ#1 has 3 shifts. It would look like this for his data:
ID presenter day hours
1 DJ#1 MON 0900-1100
2 DJ#1 TUE 0800-0900
3 DJ#1 TUE 1300-1400
Easy to understand! So, to pull his data, you would just use a SQL query like "SELECT * WHERE presenter = ‘DJ#1’ " and all
of that DJ’s schedule would be pulled and useable. To use all this data, first you have to create it. To do this, I have
created an “ADMIN” page where you can access the data and ADD/EDIT/DELETE the various “presenters”. In that same “ADMIN” page,
you can alter their shifts/days/hours… All on one page! Smooth and easy to control.
The last section of this project is a to be able to actually use this data in the live site. This can be done with ease!
All you have to do is pull the data from the database and display it. Pictures for the DJ’s or their show’s promo picture
can be loaded normally with an HREF tag. The only thing different is that you pull the URL from inside the database before it
is put on the page. This simple database project could be enhanced or improved to go even further. You could have recordings
of the DJ’s, thier latest tweets/comments that they could update themselves and played back on the website. Almost ANYTHING
you could dream up could be added to this project with ease!
Now, to the code… First there are a few setup steps. Here are the preliminary steps needed before running the code.
- Create a database in MySQL named anything you wish
- Create a table in the database named “presenters”
- Create the 6 fields above for the presenters table
- Create a table in the database named “shifts”
- Create the 4 fields above for the shifts table
- Create a folder on the site for picture storage called “djimages”
(I will need this address to finish the code. And, pictures will be moved here by the program.)
So, this is your start. I have the code mostly ready to show to you. Get the folder name to me
and read all of this. When you are understanding all of it, we will continue with the code…
ok i understand all of that and am ready for the code it seems so simple.
one thing that i thought would be a great idea but i dont know how to do it and i know i have not set this up yet but a good idea would be to have current song playing now built in.
Okay, well, I created a small ADMIN page for DJ’s for you. You will have to put your database connection info in it. And, add or delete any fields you don’t need or what to add. Since I do not know your site, I was basically guessing at what you needed. Next, I created a page to go with it that will update things when you change them.
*** I have not been home and did not have time to set up a database table to actually test this ADMIN page. I hope to do that tomorrow, but, thought you would like to have the code sooner to review…
So, here is the code for this function. Once it is all working correctly, then we would add code to your site that would pull the PROMO-picture ad’s and place them correctly in place. That code is actually quite simple.
DJ-ADMIN page: djadmin.php
[php]
DJ Administration Form! |
|
Instructions: First, select a DJ to edit or create a new one. Then, alter the data areas for that DJ. You can alter their name, description, days of the week they are schedule or hours of shifts. Remember, if multiple shifts over days or hours, they are entered each as a separate schedule. When done updating, press the "UPDATE" button and the data will be saved in the database. *** Remember once this data is stored on the database, this data will show on the "LIVE" site! |
|
Select a DJ to View/Edit/Delete: | Add New DJ! <?php $dbConn = mysql_connect(***DB_HOST,***DB_USER,***DB_PASS) or die (mysql_error()); mysql_select_db('presenters') or die (mysql_error()); // connect to your database, get names of DJs... $query = "SELECT * FROM presenters ORDER BY djname asc"; $results = mysql_query($query) or mysql_error(); // loop through the results, creating an option list, I am just using Name and Description for this test... while( $row = mysql_fetch_array($results) ) { echo "" . $row['djname] . "\n"; } ?> Add New DJ! |
DJ's Full Name: | |
DJs Nickname: | |
Description: | |
DJs Picture: | |
DJs Show Promo Picture: | |
Add New Scheduled Shift for this DJ: | Sunday Monday Tuesday Wednesday Thurday Friday Saturday 0000 to 0600 0600 to 0900 0900 to 1200 1200 to 1400 1400 to 1600 1600 to 1800 1800 to 2000 2000 to 2100 2100 to 2200 2200 to 2400 |
Updated On: | |
And, the update code: djadminupdate.php
[php]
[/php]
So, study up on these and test them. Not tested as yet, I will test it tomorrow…
it only works for me when saved as a htm file not a php file. i do not know how to do dateabases apart from add one in the hosting control panel.
i got this is so far
CREATE TABLE presenter (
id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
djname VARCHAR(80),
djnickname VARCHAR(40),
djdesc TEXT,
djpicture VARCHAR(128),
djshowpicture TINYINT UNSIGNED DEFAULT 1,
CONSTRAINT PK_presenter PRIMARY KEY (id)
) engine=innodb;
but i did do this one as well
– phpMyAdmin SQL Dump
– version 3.4.9
– http://www.phpmyadmin.net
– Host: localhost
– Generation Time: May 08, 2012 at 10:36 AM
– Server version: 5.1.57
– PHP Version: 5.2.17
SET SQL_MODE=“NO_AUTO_VALUE_ON_ZERO”;
SET time_zone = “+00:00”;
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT /;
/!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS /;
/!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION /;
/!40101 SET NAMES utf8 */;
–
– Database: web165-djpanel
–
– Table structure for table presenters
CREATE TABLE IF NOT EXISTS presenters
(
djname
text NOT NULL,
djnickname
text NOT NULL,
djdesc
text NOT NULL,
djpicture
text NOT NULL,
djshowpicture
text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT /;
/!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS /;
/!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
but all i get in the boxes are
<? echo $_SESSION['currentname']; ?> <? echo $_SESSION['currentnickname']; <? echo $_SESSION['currentdesc']; ?> <? echo $_SESSION['lastupded']; ?>Okay, you are getting there on the database. I will set one up here for testing. And, revamp the code. It will take a couple hours as I have a lot of catch-up this morning…
Basically, I would use the first version and use that query in PHP to set up the tables. Now, a couple notes…
I never use the “not null” on the text fields. The reason is that in the editor, you will see the ones that are empty and we will add a note in it to fill them in. But, if one is blank you will receive errors when it writes to the DB.
(Much easier to just display a note in the ADMIN page instead of dealing with rewrites to the DB. This will make better sense once we get it all working.) And, we will also use two tables, one for DJ info and one for their hours and shifts. I didn’t have time to explain all of that previously. We will finish this up today and hopefully have it all working soon!) In the meantime, here is a short tutorial link on how to make a connection to a database and how to send queries to it. Hope it helps…
http://www.w3schools.com/php/php_mysql_intro.asp
(I point new programmers to this page many times as it explains in a nice simple manor and makes it quite understandable! I like w3schools! Also, just click on “next chapter” to read the entire tutorial!)