Help with MYSQL Database PHP Search Engine
Posted: Mon Jan 25, 2010 2:30 pm
I am developing a MYSQL database movie search engine using php right now, i have managed to get it working where if i type the name of the film it will show the name, category, rating and description. But what i want to do is be able type the name of a film in and for it to display a random film name from a category that is called say, action, or be able to choose category, say, action from a drop down list and for it to show other films in that category and finally or be able to select a film rating from a drop down list and for it to be able to show films that have the same rating. I understand the basics of PHP pretty much and MYSQL.
But im not the skilled with it and i was just wondering if anyone could provide me with some assistance or code snippets to assist me.
Thanks in advance.
(This is my code at the moment for displaying a film, does not work too well
)
But im not the skilled with it and i was just wondering if anyone could provide me with some assistance or code snippets to assist me.
Thanks in advance.
(This is my code at the moment for displaying a film, does not work too well
Code: Select all
<?php
$host = 'localhost';
$username = 'web224-movies';
$password = 'A171294S';
$tbl_name = 'movies';
$name = $_POST['name'];
$cname =$_POST['cname'];
$cname2 =$_POST['cname2'];
$ccategory = $_POST['ccategory'];
$category = $_POST['category'];
$crate = $_POST['crate'];
$rate = $_POST['rate'];
mysql_connect("localhost", "web244-movies", "A171294S")or die("Cannot Connect please contact admin@moov.ie error code 1");
mysql_select_db("web244-movies")or die("Cannot Connect please Contact admin@moov.ie error code 2");
$name = stripslashes($name);
$name = mysql_real_escape_string($name);
$tbl_name = stripslashes($tbl_name);
$tbl_name = mysql_real_escape_string($tbl_name);
if( $cname == 'yes' && $cname2 != 'yes' ){
$sql = "SELECT * FROM `movies` WHERE Names='$name'";
$result = mysql_query($sql);
$count=mysql_numrows($result);
while ($row = mysql_fetch_assoc($result)) {
$art = $row['link'];
}
if($count == 0 ){
echo '<div id="header"><a href="/index.html" class="menubar">Click Here</a> to return to the home page.</div>
<div id="info"></div> </br> The movie does not exist in our database';
}
else{
//$head = "/results.html";
//header("location:$head");
echo '<div id="header"><a href="/index.html" class="menubar">Click Here</a> to return to the home page.</div>
<div id="info"></div> </br>', '<u>Results are show below:</u></br> </br>',
"<b>Movie Name:</b> $name",
" <b>Movie Description:</b> $description</br>";
}
mysql_free_result($result);
}
//variables search
else if($cname2 == 'yes' && $cname != 'yes'){
//Category search
if( $ccategory == 'on'){
$sql2 = "SELECT * FROM `movies` WHERE 'Category'='$category'";
$result2 = mysql_query($sql2);
$count2=mysql_numrows($result2);
while ($row2 = mysql_fetch_assoc($result2)) {
$art2 = $row2['link'];
}
if($count2 == 0 ){
echo '<div id="header"><a href="/index.html" class="menubar">Click Here</a> to return to the home page.</div>
<div id="info"></div> </br> The movie does not exist in our database';
}
else{
echo "<b>Category:</b> $category";
}
mysql_free_result($result3);
}
//rating search
if( $crate == 'on'){
$sql3 = "SELECT * FROM `movies` WHERE 'Rating'='$rate'";
$result3 = mysql_query($sql3);
$count3=mysql_numrows($result3);
while ($row3 = mysql_fetch_assoc($result3)) {
$art3 = $row3['link'];
}
if($count3 == 0 ){
echo '<div id="header"><a href="/index.html" class="menubar">Click Here</a> to return to the home page.</div>
<div id="info"></div> </br> The movie does not exist in our database';
}
else{
echo "<b>Rating:</b> $rate";
}
mysql_free_result($result3);
}
//$categorysql= stripslashes($categorysql);
//$categorysql = mysql_real_escape_string($categorysql);
//$ratesql= stripslashes($ratesql);
//$ratesql = mysql_real_escape_string($ratesql);
$sql2 = "SELECT * FROM $tbl_name WHERE $categorysql $ratesql";
$result2 = mysql_query($sql2);
$num = mysql_numrows($result2);
//echo $sql2; for testing sql
while( $i < $num){
$field1 = mysql_result($result2,$i,"Category");
$field2 = mysql_result($result2,$i,"Rating");
echo "<br><a href=/reviews/$field1>$field2</a></br>";
$i++;
}
}
else { echo "We cannot find the film you are looking for.";
}
?>