Another PHP/MySQL template

If you made a template for printing or HTML export, you can offer it to the others here. You can also ask here for help about these templates
Post Reply
stalker
Posts: 5
Joined: 2006-03-21 07:56:51

Another PHP/MySQL template

Post by stalker »

Here is a PHP/MySQL based template that I use for my personal movie collection:

http://www.jrobin.org/~saxon/amc/movies.php

If you like it, here are the instructions, step by step:

1) Export your movie collection (and thumbnail images) by using AMC's SQL export. The following fields must be exported: number, media label, rating, original title, translated title, directory, country, year, length, actors, url, description, comments, subtitles, category.

2) Use SQL file to create movie database on your mysql webserver (I hope that you know how to do that). The template expects that your database is named 'movies' with a single table in it named 'movies' containing records from the SQL file.

3) Create an empty directory on your PHP/MySQL enabled webserver

4) Put the following files in it:

db.php

Code: Select all

<?
$link = mysql_pconnect('localhost', 'your_database_username', 'your_database_password')
	or die('Could not connect: ' . mysql_error());
mysql_select_db('movies') 
	or die('Could not select database');
?>
full.php

Code: Select all

<?
include 'db.php';
ob_start();

$field = "NUM";
if(isset($_GET['field']) && is_numeric(($_GET['field']))) {
	switch ((int) $_GET['field']) {
		case 0: $field = "NUM"; break;
		case 1: $field = "ORIGINALTITLE"; break;
		case 2: $field = "YEAR"; break;
		case 3: $field = "DIRECTOR"; break;
		case 4: $field = "RATING"; break;
	}
}

$order = "DESC";
if(isset($_GET['order']) && is_numeric(($_GET['order']))) {
	$order = ((int) $_GET['order']) == 0? "ASC": "DESC";
}

$query = "SELECT NUM, MEDIA, ORIGINALTITLE, DIRECTOR, YEAR, TRANSLATEDTITLE, RATING " .
	"FROM movies ORDER BY $field $order";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$movie_count = mysql_num_rows($result);
?>

<html>
<head>
<LINK REL="stylesheet" href="movies.css" TYPE="text/css">
</head>
<body>
<form method="GET" action="<? echo $PHP_SELF ?>">
<table border="0" cellspacing="0" cellpadding="0" width="100%" align="center">
<tr><td>
	<table border="0" cellspacing="0" cellpadding="4">
		<tr>
			<td bgcolor="red" colspan="2">
			<b>Order <font color="yellow" size="+1"><? echo $movie_count ?></font> movies by:</b>
			<select name="field">
				<option value="0" <? if(strcmp($field, "NUM") == 0) echo "selected" ?>>ID</option>
				<option value="1" <? if(strcmp($field, "ORIGINALTITLE") == 0) echo "selected" ?>>Title</option>
				<option value="2" <? if(strcmp($field, "YEAR") == 0) echo "selected" ?>>Year</option>
				<option value="3" <? if(strcmp($field, "DIRECTOR") == 0) echo "selected" ?>>Director</option>
				<option value="4" <? if(strcmp($field, "RATING") == 0) echo "selected" ?>>Rating</option>
			</select>
			<select name="order">
				<option value="0" <? if(strcmp($order, "ASC") == 0) echo "selected" ?>>ASC</option>
				<option value="1" <? if(strcmp($order, "DESC") == 0) echo "selected" ?>>DESC</option>
			</select>
			<input type="submit" value="Refresh">			
			</td>
		</tr>

<?
while ($m = mysql_fetch_assoc($result)) {
	$link = "item.php?id=" . $m['NUM']; ?>
	<!-- SINGLE MOVIE -->
	<tr>
		<td class="lgt" width="30"><b><? echo $m['NUM'] ?></b></td>
		<td class="lgt">
			<b><a href="<? echo $link ?>" target="rightfr" class="lgt"><? echo $m['ORIGINALTITLE'] ?></a></b>
			<? if($m['YEAR'] != null && strlen($m['YEAR']) > 0 && (int)$m['YEAR'] > 0) echo "(" . $m['YEAR'] . ")" ?>
			<? if($m['DIRECTOR'] != null && strlen($m['DIRECTOR']) > 0) echo "by " . $m['DIRECTOR'] ?>
			<? echo $m['MEDIA'] ?>
			<? if($m['TRANSLATEDTITLE'] != null && strlen($m['TRANSLATEDTITLE']) > 0) echo "<br><i>" . $m['TRANSLATEDTITLE'] . "</i>" ?>
		</td>
	</tr>

<? } ?>

	</table>
</td></tr>
</table>
</form>
</body>
</html>

<?
mysql_free_result($result);
ob_end_flush(); 
?>
item.php

Code: Select all

<?
include 'db.php';

function imgtag($n) {
	return "<img class='noborder' src='g$n.gif' width='20' height='18'>";
}

function paragraph($s, $class) {
	$p = explode("|", trim($s));
	$r = "<p class='$class'>";
	for($i = 0, $n = count($p); $i < $n; $i++) {
		$r .= $p[$i];
		if($i < $n - 1) {
			$r .= '<br>';
		}
	}
	$r .= '</p>';
	return $r;
}

function rating($valueStr) {
	$result = 'Not rated yet';
	if($valueStr != null && strlen($valueStr) > 0) {
		$value = (float) $valueStr;
		if($value > 0.0 && $value <= 10.0) {
			$stars = floor($value);
			$remain = $value - $stars;
			$shades = 10;
			$result = '';
			for($i = 0; $i < $stars; $i++) {
				$result .= imgtag(1);
				$shades--;
			}
			if($remain >= 0.5) {
				$result .= imgtag(2);
				$shades--;
			}
			for($i = 0; $i < $shades; $i++) {
				$result .= imgtag(3);
			}
			$result .= sprintf(" <b>%4.1f</b>", $value);
		}
	}
	return $result;
}

// DATA FETCHING
$id = $_GET['id'];
is_numeric($id) or die("Invalid parameter supplied");
$query = "SELECT * FROM movies WHERE num=$id";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
if($m = mysql_fetch_assoc($result)) {
?>

<html><head>
<LINK REL="stylesheet" href="movies.css" TYPE="text/css">
</head><body class="moviecard">
<table class="lgt" cellspacing="0" cellpadding="5">
<tr><td class="lgt">
<table class="i" border="0" cellspacing="0" cellpadding="1" width="100%">
<tr>
	<td colspan="3" class="iblk"><div class="title">
  	<? echo $m['ORIGINALTITLE']?>
	<? if ($m['YEAR'] != null && strlen($m['YEAR']) > 0 && (int)$m['YEAR'] > 0) echo "(" . $m['YEAR'] . ")" ?>
	</div></td>
</tr>
<tr>
  <td class="iwh" rowspan="6" width="120"><img src="<? echo $m['PICTURENAME'] ?>" alt="poster" /><br>
  Box: <? echo $m['MEDIA']; ?><br>
  <a href="<? echo $m['URL'] ?>">Check IMDB</a></td>
  <td class="igr"><b>Director:</b></td>
  <td class="iwh"><b><? echo $m['DIRECTOR'] ?></b></td></tr>
  <td class="igr"><b>Rating:</b></td>
  <td class="iwh">
  	<? echo rating($m['RATING']) ?>
  </td></tr>
  <td class="igr"><b>Actors:</b></td>
  <td class="iwh"><? echo $m['ACTORS'] ?></td></tr>
  <td class="igr"><b>Country:</b></td>
  <td class="iwh"><? echo $m['COUNTRY'] ?></td></tr>
  <td class="igr"><b>Category:</b></td>
  <td class="iwh"><? echo $m['CATEGORY'] ?></td></tr>
  <td class="igr"><b>Length:</b></td>
  <td class="iwh"><? echo $m['LENGTH'] ?> mins</td></tr>
</table><hr class="blk">
<table class="i" border="0" cellspacing="0" cellpadding="1">
<tr>
  <td class="igr" width="120"><b>Other titles:</b></td>
  <td class="iwh"><? echo $m['TRANSLATEDTITLE'] ?></td></tr>
  <td class="igr" width="120"><b>Description:</b></td>
  <td class="iwh"><? echo paragraph($m['DESCRIPTION'], "iwhi") ?></td></tr>
  <td class="igr"><b>Comments:</b></td>
  <td class="iwh"><? echo paragraph($m['COMMENTS'], "iwh") ?></td></tr>
  <td class="igr"><b>Subtitles:</b></td>
  <td class="iwh"><? echo $m['SUBTITLES'] ?></td></tr>
</table>
</tr></td></table></body></html>

<? } 
mysql_free_result($result);
?>
movies.css

Code: Select all

td.nbr
{
  FONT-SIZE: 14pt;
  FONT-FAMILY: Trebuchet MS, Verdana, Arial, Helvetica, sans-serif;
  weight: bold;
  color: white;
  background: black;
}

body
{
  margin: 0px;
  padding: 0px;
  color: white;
  background: black;
}

body.moviecard
{
  margin: 1px;
  padding: 1px;
  color: white;
  background: black;
}

input, select {
  FONT-SIZE: 8pt;
  FONT-FAMILY: Trebuchet MS, Verdana, Arial, Helvetica, sans-serif;
  color: black;
  background: white;
  vertical-align: top;
}

text, p, div, span, th, td, ul, li
{
  FONT-SIZE: 10pt;
  FONT-FAMILY: Trebuchet MS, Verdana, Arial, Helvetica, sans-serif;
  color: white;
  background: black;
  vertical-align: top;
}

HR.blk
{
  border: solid;
  border-color: black;
}

HR
{
  border: solid;
  border-color: #AFEEE6;
}

td.lgt, table.lgt, text.lgt, p.lgt
{
  color: black;
  background: white;
  border: solid;
  border-width: 1px;
  border-color: black;
  vertical-align: top;
}

a.lgt:link
{
  color: #0000AA;
  background: #ffffff;
  text-decoration: none;
}

a.lgt:active
{
  color: #0C4D45;
  background: #ffffff;
  text-decoration: underline;
}

a.lgt:visited
{
  color: #000050;
  background: #ffffff;
  text-decoration: none;
}

a.lgt:hover
{
  color: #FF0000;
  background: #ffffff;
  text-decoration: underline;
}

.noborder
{
  background: white;
  border: none;
  border-width: 0px;
  border-color: #FFFFFF;
}

td, table
{
  color: white;
  background: black;
  border: solid;
  border-width: 1px;
  border-color: black;
}

A:link
{
  COLOR: black;
  background: white;
  text-decoration: underline;
}

A:visited
{
  COLOR: black;
  background: white;
  text-decoration: none;
}

A:hover
{
  COLOR: red;
  background: white;
  text-decoration: underline;
}

A:active
{
  COLOR: black;
  background: white;
  text-decoration: underline;
}

td.iwh, table.iwh, text.iwh
{
  color: black;
  background: white;
  border: solid;
  border-color: white;
  vertical-align: top;
}

p.iwh
{
  color: black;
  background: white;
  vertical-align: top;
}

p.iwhi
{
  color: black;
  background: white;
  vertical-align: top;
  font-style: italic;
}

td.igr, text.igr
{
  color: black;
  background: #F9F6FD;
  border: solid;
  border-width: 2px;
  border-color: white;
  vertical-align: top;
}

td.iblk, text.iblk
{
  color: white;
  background: black;
  border: solid;
  border-color: black;
  vertical-align: top;
}

table.i
{
  color: black;
  background: white;
  border: none;
}

div.title
{
  font-size: 18pt;
  font-weight: bold;
  text-align: left;
  color: white;
  background: black;
}

img 
{
	border: solid;
	border-color: black;
	border-width: 1px;
}
movies.php

Code: Select all

<?
include 'db.php';

$query = "SELECT MAX(NUM) AS id FROM movies";
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
if($m = mysql_fetch_assoc($result)) {
	$id = rand(1, $m['id']);
?>
<html>
<head>
<title>My Movies</title>
</head>
<frameset cols="400,*">
<frame src="full.php" name="leftfr" marginheight="0" marginheight="0">
<frame src="item.php?id=<? echo $id ?>" name="rightfr" marginheight="0" marginheight="0">
</frameset>
</html>
<? } 
mysql_free_result($result);
?>
5) Pick these 3 gifs:

ImageImageImage

...and put them in the same directory along with your PHP files

6) Copy all your thumbnail images exported from AMC to the directory with your PHP files.

7) DONE! Open movies.php file with your browser and enjoy.

FUTURE UPDATES: You should only update your MySQL database and upload new thumbnails to the server.
Post Reply