ddrueding
Fixture
In order to have different links to different searches, I'll need to do the hyperlinks based on the tokenized results? I haven't felt this stupid in a long time.
<a href='./search.php?search=tag1'>tag1</a> <a href='./search.php?search=tag2'>tag2</a>....
// Outputs HTML results in a table, given a mysql object
function displayMovies($listings)
{
echo "<table width='60%' cellspacing='0' cellpadding='0' border='1' align=center>
<tr><td><b>Title</b></td><td><b>Tags</b></td></tr>\n";
//Loop through results
while($row = mysql_fetch_array($listings))
{
echo "<tr><td><a href='".$row['location1']."'>".$row['title']."</a></td><td>".makeTags($row['index'])."</td></tr>\n";
}
echo "</table>\n";
}
function makeTags($id)
{
// Lookup
$result = select tags from movies where movies.index = '$id';
$result = mysql_fetch_row($result);
//tokenize
...
// Loop through tokens
for each ...
{
// Build string of html
$html .= "...";
}
return $html;
}
Got #3 working the was I wanted by un-doing a bunch of Blake's work...sorry about that.
I almost have #1 working as I want; the location is in the hyperlink, but it still starts with the server's address (http://192.168.1.7/ z:\movies\animated\Cinderella.avi )
Also you might want to read up on php/mysql security, including use of the root user for a php app like this and use of the mysql_real_escape_string() php function to guard against unintended input characters.
That's one of my favorite xkcd comics. Fits perfectly here.
function makeTags($id)
{
// Lookup
$result = "SELECT tags FROM movies WHERE movies.index = '$id'";
$result = mysql_fetch_row($result);
// Tokenize
$tokens = explode(" ", $result);
// Loop through tokens
foreach($tokens as $token);
{
// Build string of HTML
$html .= "<a href='./movies.php?search="$token"'>"$token"</a> ";
}
return $html;
}
btw, index is a reserved word in my version of MySQL (5.x)... perhaps id would be a better choice of column name so that you do not have to prepend the table name when performing queries...
Great idea. What is a logical choice?
1: function makeTags($id)
2: {
3:
4: // Lookup
5: $result = "SELECT tags FROM movies WHERE movies.index = '$id'";
6: $result = mysql_fetch_row($result);
7:
8: // Tokenize
9: $tokens = explode(" ", $result);
10:
11: // Loop through tokens
12: foreach($tokens as $token);
13: {
14: // Build string of HTML
15: $html .= "<a href='./movies.php?search="$token"'>"$token"</a> ";
16: }
17:
18: return $html;
19:}
echo "My name is $name and I am $age";
echo 'My name is '.$name.' and I am '.$age;
echo "My name is $name and I am ".$age;
<?php
form();
process();
// Display search form
function form()
{
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
Search: <input type="text" name="search" /><input type="submit"/>
</form>
<?
}
// Perform the search
function process()
{
// Connect to DB
mysql_connect("localhost", "movies", "movies") or die(mysql_error());
mysql_select_db("movies") or die(mysql_error());
// Clean user input of escape characters
$search = mysql_real_escape_string($_GET['search']);
// Get search results
$results = queryMovie($search);
if($results) // If there were results, output them
{
// Output html results
displayMovies($results);
}
else // Report Nothing found
{
echo "\n<br>Nothing Found. Please try again. <br><br>\n";
}
}
// Queries DB for movie listings, returns false if query fails or no results;
function queryMovie($search)
{
// Tokenize search query
$tokens = explode(" ", $search);
// Build search query from tokens
$query = "SELECT * FROM movies WHERE ";
$query .= "movies.index > 0 ";
foreach($tokens as $token)
{
if(substr($token,0,1) == "+") // Token contains +
{
//Strip +
$token = substr($token, 1, strlen($token));
$query .= " AND (tags LIKE '%$token%')";
}
elseif(substr($token,0,1) == "-") // Token contains -
{
//Strip -
$token = substr($token, 1, strlen($token));
$query .= " AND (tags NOT LIKE '%$token%')";
}
else // Bare token
{
$query .= " AND (title LIKE '%$token%' OR tags LIKE '%$token%')";
}
}
// Debugging
//echo "<code>$query</code>\n";
$results = mysql_query($query);
if(mysql_num_rows($results) == 0)
return FALSE;
else
return $results;
}
// Outputs HTML results in a table, given a mysql object
function displayMovies($listings)
{
echo "<table width='100%' cellspacing='0' cellpadding='0' border='1'>
<tr><td><b>Title</b></td><td><b>Tags</b></td></tr>\n";
//Loop through results
while($row = mysql_fetch_array($listings))
{
echo "<tr><td><a href='".$row['location1']."'>".$row['title']."</a></td><td>".makeTags($row['tags'])."</td></tr>\n";
}
echo "</table>\n";
}
// Tokenizes a string of tags and returned returns them as HTML formatted links
function makeTags($tags)
{
// Tokenize
$tokens = explode(" ", $tags);
$html = "";
// Loop through tokens
foreach($tokens as $token)
{
// Build string of HTML
$html .= "<a href='./movies.php?search=$token'>$token</a> ";
}
return $html;
}
?>
Try it, and if/when you have questions, post them so we can help. Their API seems to be Object Oriented and reasonably documented. How much have you done with that be it PHP or any other language? It does look interesting, but I see it as a tool to query the IMBD database, not your own.
What are thoughts with using this tool/API? I guess you could make it more like your own IMDB and then have it pull in real data about each movie. You could extend their API and have it search locally, but your local sight would have to work similar to IMDB. It might be a fun project if you're interested.
I can already think of some fun things to add, like your own "view" counters when you click the "watch this movie" button (which also shows you the last time you watched the movie), or your own
random suggest" based on moods, or even a que of movies you want to watch, yet it remembers them for you with e-mail reminders...weird things like that.
Looks like the author of that also wrote phpVideoPro. Looking into it more.
I honestly just saw that 30 seconds ago and you posted it. That seems more practical.
echo $movie->title().',';
echo $movie->year().',';
$gen = $movie->genres();
for ($i = 0; $i + 1 < count($gen); $i++) {
echo $gen[$i].',';
}
$cast = $movie->cast();
for ($i = 0; $i + 1 < count($cast); $i++) {
echo $cast[$i].',';
}
$director = $movie->director();
for ($i = 0; $i + 1 < count($director); $i++) {
echo $director[$i].',';
}
$write = $movie->writing();
for ($i = 0; $i + 1 < count($write); $i++) {
echo $write[$i].',';
}
$produce = $movie->producer();
for ($i = 0; $i + 1 < count($produce); $i++) {
echo $produce[$i].',';
}
$compose = $movie->composer();
for ($i = 0; $i < count($compose); $i++) {
echo $compose[$i].',';
}
foreach ( $movie->alsoknow() as $ak){
echo $ak["title"];
}
Ice Age,2002,Adventure,Animation,Family,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,The Ice Age
$movie = new imdb ($_GET["mid"]);
$movieid = $_GET["mid"];
$movie->setid ($movieid);
echo $movie->title().',';
echo $movie->year().',';
$gen = $movie->genres();
for ($i = 0; $i + 1 < count($gen); $i++) {
echo $gen[$i].',';
}
foreach ( $movie->cast() as $cas){
echo $cas.',';
}
foreach ( $movie->director() as $dir){
echo $dir.',';
}
foreach ( $movie->writing() as $wri){
echo $wri.',';
}
foreach ( $movie->producer() as $pro){
echo $pro.',';
}
foreach ( $movie->composer() as $com){
echo $com.',';
}
foreach ( $movie->alsoknow() as $ak){
echo $ak["title"];
}
<HTML>
<HEAD><TITLE>Enter IMDB Movie ID:</TITLE></HEAD>
<BODY>
<FORM ACTION="david.php" METHOD=get>
<INPUT TYPE="text" NAME="imdbid" SIZE=30 MAXLENGTH=50>
<INPUT TYPE="submit" VALUE="Submit">
</FORM>
</BODY>
</HTML>
<?php
require ("imdb.class.php");
$movie = new imdb ($_GET["imdbid"]);
$movieid = $_GET["imdbid"];
$movie->setid ($movieid);
echo $movie->year().',';
foreach ( $movie->genres() as $gen){
echo $gen.',';
}
foreach( $movie->cast() as $cas){
echo $cas.',';
}
foreach( $movie->director() as $dir){
echo $dir.',';
}
foreach( $movie->writing() as $wri){
echo $wri.',';
}
foreach( $movie->producer() as $pro){
echo $pro.',';
}
foreach( $movie->composer() as $com){
echo $com.',';
}
foreach( $movie->alsoknow() as $ak){
echo $ak["title"];
}
?>
1997,Thriller,Crime,Drama,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,Array,
try adding another foreach() inside the items that show "Array" as a result. It looks like a multi-dimensional array.
PHP:foreach( $movie->cast() as $cas){ foreach($cas as $castItem) { echo $castItem.','; } }
<?php
require ("imdb.class.php");
$movie = new imdb ($_GET["imdbid"]);
$movieid = $_GET["imdbid"];
$movie->setid ($movieid);
echo $movie->year().',';
foreach ( $movie->genres() as $gen){
echo $gen.',';
}
foreach( $movie->cast() as $cas){
echo $cas["name"].',';
}
foreach( $movie->director() as $dir){
echo $cas["name"].',';
}
foreach( $movie->writing() as $wri){
echo $cas["name"].',';
}
foreach( $movie->producer() as $pro){
echo $cas["name"].',';
}
foreach( $movie->composer() as $com){
echo $cas["name"].',';
}
foreach( $movie->alsoknow() as $ak){
echo $ak["title"];
}
?>
1995,Drama,Sci-Fi,Thriller,Joseph Melito,Bruce Willis,Jon Seda,Michael Chance,Vernon Campbell,H. Michael Walls,Bob Adrian,Simon Jones,Carol Florence,Bill Raymond,Ernest Abuba,Irma St. Paule,Madeleine Stowe,Joey Perillo,Bruce Kirkpatrick,Wilfred Williams,Rozwill Young,Brad Pitt,Nell Johnson,Frederick Strother,Rick Warner,Frank Gorshin,Anthony 'Chip' Brienza,Joilet Harris,Drucie McDaniel,John Blaisse,Louis Lippa,Stan Kang,Pat Dias,Aaron Michael Lacey,David Morse,Charles Techman,Jann Ellis,Johnnie Hobbs Jr.,Janet Zappala,Thomas Roy,Harry O'Toole,Yuri Korchenko,Chuck Jeffreys,Lisa Gay Hamilton,Felix Pire,Matt Ross,Barry Price,John Panzarella,Christopher Plummer,Larry Daly,Arthur Fennell,Karl Warren,Christopher Meloni,Paul Meshejian,Robert O'Neill,Kevin Thigpen,Lee Golden,Joseph McKenna,Jeff Tanner,Faith Potts,Michael Ryan Segal,Annie Golden,Lisa Talerico,Stephen Bridgewater,Ray Huffman,Jodi Dawson,Jack Dougherty,Lenny Daniels,Herbert C. Hauls Jr.,Charley Scalies,Carolyn Walker,Tiffany Baldwin,C.J. Byrnes,Phillip V. Caruso,Cathy D'Arcy,John Hagy,Adam Hatley,Julie Mabry,Sal Mazzotta,Roger Pratt,Allelon Ruggiero,Richard Stanley,Richard Stanley,Richard Stanley,Richard Stanley,Richard Stanley,
<?php
require ("imdb.class.php");
$movie = new imdb ($_GET["imdbid"]);
$movieid = $_GET["imdbid"];
$movie->setid ($movieid);
echo $movie->year().',';
foreach ( $movie->genres() as $gen){
echo $gen.',';
}
foreach( $movie->cast() as $cas){
echo $cas["name"].',';
}
foreach( $movie->director() as $dir){
echo $dir["name"].',';
}
foreach( $movie->writing() as $wri){
echo $wri["name"].',';
}
?>
foreach ( $movie->genres() as $gen){