Okay, your last comments bring up full circle back to the “Dynamic” code I was talking about. Basically you use a html button with on Onclick option at the end. The onclick sends the code to a Javascript routine. The routine pulls a variable that was stuffed into an array when loading the page. The variable would be one playlist. You will be limited on how many playlist you can stuff into an array. Some browser crap out if you load too much. You can play with that… The Java routine would take this data from the array and update the JW data with the new one. I am not sure about how JW handles playlists. If it loads it on page-load, then you may have to refresh the page to make it work. Since a user would be clicking a playlist tag or button, it would not matter if the page refreshes. They would still get their new videos…
First, I think the ADMIN or PlaylistCreator page should be done. One you get some playlists together, THEN work on getting them on your PlayerPage… So, first you will need these code parts to accomplish it all:
- a simple way to get your videos on screen to be able to edit, update, delete or add new ones.
(This is simple code and I will give it to you further down this post.)
- a simple list of the current playlists and same with the videos, a way to edit update delete and add.
(Basically the same code, just with different fields and data…)
- Perhaps a sample area that would be exactly like your PlayerPage that would “DEMO” the newly added
or edited playlist.
You can put your videos onscreen in some sort of scrollable listbox, but, I just use a SELECT-OPTION dropdown. I find this will take very little screen space and works very well. The only time this does not work well is when there are a very large number of items. If you have 1000 videos, you will not be able to use a drop-down. (Unless you divide the videos based on a criteria such as first letter (alphabetically) or based on type of music or whatever… That would be your decision. But. for now , let’s use a dropdown for testing.
Here is a simple page with code to load names of videos into a dropdown:
First a few notes on this code. There is no error checking, little needed, so didn’t put any in. The select dropdown pulls the video name and descriptions and also creates a tricky VALUE with both name and description. This is PASSED ONTO the javascript code which separates the values and populates the two text boxes. Since these text boxes are inside the form, they are passed to the second php page which updates the database. Okay, let’s look at the form page which will be the actual admin page. (Later, you can add in the playlist admin page, but, for now let’s get the video part working…
File VideoADMIN.php (NOTE: You will have to add in all of your fields, etc.)
<!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>Untitled Document</title>
</head>
<?PHP
$hostname='zzzzzzzzzzzzzz.com';
$username = "zzzz";
$password = "zzzz";
$dbname = "zzzzzz";
?>
<script language="JavaScript" type="text/javascript">
function videochanged(){
var VideoDataArray = document.getElementById('VideoSelect').value.split('|');
document.getElementById('VideoName').value = VideoDataArray[0];
document.getElementById('VideoDescription').value = VideoDataArray[1];
}
</script>
<body>
<form id='VideoAdminForm' name="VideoAdminForm" action='VideoADMINupdate.php' method='post'>
<br /><center>Video Editor<br /><br />
Select Video Name:<SELECT ID="VideoSelect" NAME="VideoSelect" onchange="videochanged();">
<?php
// connect to your database, get data about your video list...
$dbConn = mysql_connect( $hostname, $username, $password );
@mysql_select_db($dbname);
$query="SELECT * FROM Videos";
$results = mysql_query ( $query, $dbConn);
// loop through the results, creating an option list, I am just using Name and Description for this test...
while( $row = mysql_fetch_row($results) ) {
print "<CENTER><OPTION VALUE='" . $row[1] . "|" . $row[3] . "'" . ">" . $row[1] . "</OPTION>\n"; //NOTE: row(1) is videoname row(3) is descriptions field
}
print "<OPTION VALUE=\"Enter a new Video name here...|Video Description goes here...\">Add New Video!</OPTION>\n";
mysql_close($dbConn);
?>
</SELECT>
<br /><br /><br /><br />ALTER/UPDATE fields below...<br /><br /><br />
<input id='VideoID' name='VideoID' type='hidden' VALUE='' />
Video Name : <input id='VideoName' name='VideoName' type='text' VALUE='' size='70'>
<br /><br />
Video Description : <input id='VideoDescription' name='VideoDescription' type='text' VALUE='' size='70'>
<br /><br />
<input type="submit" name="UpdateVideo" value="Update This Video!" />
<br /><br /><br />
<input type="submit" name="DeleteVideo" value="Delete This Video!" />
</center>
</form>
</body>
</html>
Now that you have a form with your videos, you have to UPDATE or DELETE your changes. This is done in the second file. It reads the post and handles it all, then returns to the ADMIN page so another update can be handled. Remember, all of this post is just about videos, you will do the same two pages for a playlist process. I also add a field called “LastUpdated” to my database video and plylist tables. I use this in logs and reports to let me know if the data is up to date. This timestamp is nice as an added feature. For updates, it tries it first. If it fails it does an insert instead. This way if you mistype the name, it will still insert it. Of course, we have to add in the thumbnail upload. (This is done on the ADMIN page and will load the thumbnail from your local drive and resize it automatically for you. Here is the posting page…
VideoADMINupdate.php
<?PHP
SESSION_START();
//print_r($_POST);
//die();
// Set up database connection...
$hostname = "zzzzzzzzzzz.com";
$username = "zzzzzzzzz";
$password = "zzzzzzzzz";
$dbname = "zzzzzzz";
$dbConn = mysql_connect( $hostname, $username, $password );
@mysql_select_db($dbname);
// Handle Video Updates...
if(isset($_POST['UpdateVideo'])) {
// Update the Video's data, if it does not exist then insert new version...
$query = "UPDATE Videos SET VideoName='" . $_POST['VideoName'] . "'VideoDescription='" . $_POST['VideoDescription'] . "', LastUpdated='" . date('Y-m-d H:i:s'). "' WHERE VideoName = '" . $_POST['VideoName'] . "'";
$result = mysql_query ( $query, $dbConn );
//echo("QUERY=" . $query); echo("<br>records=" . mysql_affected_rows());
if (mysql_affected_rows()==0) {
$query = "INSERT INTO Videos (VideoName, VideoDescription, LastUpdated) VALUES ('" . $_POST['VideoName'] . "', '" . $_POST['VideoDescription'] . ", '" . date('Y-m-d H:i:s') . "')";
$result = mysql_query ( $query, $dbConn );
}
}
if(isset($_POST['DeleteVideo'])) {
// Delete the Video...
$query = "DELETE FROM Videos WHERE VideoName = '" . $_POST['VideoName'] . "'";
$dbResID = mysql_query ( $query, $dbConn );
}
mysql_close( $dbConn );
// After update or delete is completed, go back to ADMIN page...
header("Location: VideoADMIN.php");
?>
<html>
</html>
Take the above code and create your ADMIN page for the videos. Add in all the other fields I left out. Once it is working, then you can make the same two pages for the Playlists. I will send you some code to create the playlists. Right now, you just need the select parts…
Good luck…