hi everyone, I am actually very new to php and mysql… I am creating my web site and i want to have a search on the pages, i had created the datebase …i had check some tutorials on the web but i havent been able to understand it or it doesnt work…plz ,plz if someone can give me a little of orientation and help me with this i will appreciated thnks
Here is a great source for real world practical use tutorials - http://youtube.com/phpacademy and here is a link to the search engine tutorial http://www.youtube.com/watch?v=u90HAXKFmq4
Searching is similar to selecting, just a few minor changes.
Connect to the DB using PDO dbconnect.php:
[php]
//Set the host, username, password and db name in variables
$db_myHost = “localhost”;
$db_myUser= “user”;
$db_myPassword = “pass”;
$db_myDatabase = “db”;
//Connect to the db
$dbconn = new PDO(‘mssql:host=’.$db_myHost.’;dbname=’.$db_myDatabase, $db_myUser, $db_myPassword);
//Test the connection
try
{
$dbPDO = new PDO(‘mssql:host=’.$db_myHost.’;dbname=’.$db_myDatabase, $db_myUser, $db_myPassword);
$dbPDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e)
{
//echo "Error!: " . $e->getMessage() . "
die();
}
[/php]
Search using a form search.php:
[php]
//Declare the search term
$query->execute(array(’:title’=>"%$q%"));
//Get the results
$results = $query->fetchAll();
//Enter the results into a foreach loop
foreach ($result AS $results){
//Output the result
echo "$result[‘title’];
}else {
//form wasnt subitted show the form
echo ’
'; } ?> [/php]
That’s just a basic example.