I sorta volunteered to help someone improve their website, but am not sure where to begin?! (Oops!)
The simple version goes like this…
Each week the website in discussion displays a “playlist” of music that will be played for a show.
The problem is that after the show, the list is changed and so there is no history.
Certain people want to be able to go back and see what was played last week, two weeks ago, or two months ago.
So I suggested that the “Playlists” be put in a database - simple table likely - and allow users to select a given week and then have website display the given week.
Doing this will help the webmaster more easily manage “Playlists” and it will allow users to see the archived lists without taking up too much space on the website.
There is a radio station in Chicago that has example what I am suggesting located here.
How would you tackle this if you were using PHP and MySQL?
(Since I am still learning both, I’m not sure where to begin?!)
The presentation part (iterating the array of playlists to display the select) is fairly down and dirty procedural. It just happens to get that data from the get_recent_playlists() method. So you can put the Playlists class in another file and include it which keeps it out of the way.
If you would like a quick and simple demo of a class (object) hopefully this demo code will give you an idea of how classes work.
If you use the KISS principle and remember that classes basically consist of properties and methods to use/manipulate those properties then you should pick up at least the basics of OOP’ing pretty quickly.
<?php
class Book {
//class properties
private $title;
private $author;
/*------------------------------------------------------------
**** Class Methods *****
------------------------------------------------------------*/
public function __construct($newTitle, $newAuthor) {
$this->title = $newTitle;
$this->author = $newAuthor;
}
public function setTitle($newTitle) {
$this->title = $newTitle;
}
public function setAuthor($newAuthor) {
$this->author = $newAuthor;
}
public function getTitle() {
return $this->title;
}
public function getAuthor() {
return $this->author;
}
} //end of class. The above code would normally be stored in a separate php file
//testing code
//first create 2 new books
$mybook1 = new Book('OOP is Great','Fred Smith');
$mybook2 = new Book('I like OOP','Sam Jones');
//now display the current values stored in each book
echo 'Book 1 title = '.$mybook1->getTitle().'<br />';
echo 'Book 1 author = '.$mybook1->getAuthor().'<br />';
echo 'Book 2 title = '.$mybook2->getTitle().'<br />';
echo 'Book 2 author = '.$mybook2->getAuthor().'<br /><br />';
//now change some values in each book
$mybook1->setTitle('OOP is Great - 2nd Edition');
$mybook2->setAuthor('John Smith');
//now display the current values stored in each book
echo 'Book 1 title = '.$mybook1->getTitle().'<br />';
echo 'Book 1 author = '.$mybook1->getAuthor().'<br />';
echo 'Book 2 title = '.$mybook2->getTitle().'<br />';
echo 'Book 2 author = '.$mybook2->getAuthor().'<br /><br />';
?>
The first thing you would need to do before any coding is to build the database. You don’t want to be half way through coding your website and then realise…oooopss!!..my database structure is wrong.
In its simplest form you could have 2 tables similar to this
tblSongs
-----------
songID
title
tblPlaylists
-------------
playListID
name
songID
showDate
where songID in tblPlaylists must first exist in tblSongs.
Once your database is set up, then you can start coding to update and display records in the database as required.
For those too shy to visit my link above, here is what the output would look like… (Different content - obviously - but similar format.)
[COLOR=“green”][SIZE=“2”]ROCK & ROLL ROOTS FOR 08.29.10
Out in the Country
Joe Walsh - In the City
Foghat - Fool For the City
The Beach Boys - Then I Kissed Her
Bruce Springsteen - Blinded By the Light
Manfred Mann - Spirit in the Night
Neil Young - Are You Ready for the Country
Elton John - Country Comfort
The Mamas and The Papas - Go Where You Wanna Go
Fleetwood Mac - Monday, Monday
James Taylor - Country Road
Steve Miller Band - Going to the Country
[/SIZE][/COLOR]