Hi friends,

I need a simple help or query for my search option in my website. I had a table which storing movie information. The rough form of table structure as follows.

Movie name | Director | Genre | Producer | Story line | Cast
-------------------------------------------------------------------
| | | | |


When user type any word in search box and then hit "search " button I need to search on this complete table and shows the result. I am very new with these type of queries. Please help me

Thanks in advance
Rajeesh

Recommended Answers

All 2 Replies

A prepared statement query to do using PDO
Lets say that
Data Base name: $database
Host: $host
Data Base User Name: $dbUser
DB password: $dbUserPasswod
Table: $table
Search Term: $search

<?php
$db = new Pwf_Data_Db('mysql:dbname=$database;host=$host,$dbUser,$dbUserPasswod');
$query = "SELECT * FROM $table WHERE Movie_name LIKE ? OR Director LIKE ? OR Genre LIKE ? OR Producer LIKE ? OR Story_line LIKE ? OR Cast LIKE ?";
$statement = $db->prepare($query);
$statement->execute(array("%".$search."%","%".$search."%","%".$search."%","%".$search."%","%".$search."%","%".$search."%"));
$result = $statement->fetchAll(PDO::FETCH_ASSOC);
?>

So with that $result will be an array with all the results. Of course this code is just a sample and doesn’t handle any exception. Also a small advice… use a unified name concession for example Movie_Name but you can make your own as long as it is unified (in order your code to make sense) .


and also lets say that table fields you provided have _ between words

sorry not

$db = new Pwf_Data_Db('mysql:dbname=$database;host=$host,$dbUser,$dbUserPasswod');

but

$db = new PDO('mysql:dbname=$database;host=$host,$dbUser,$dbUserPasswod');
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.