Hi all,
To all gurus in PHP, i know this is just a piece of cake….but i confess, during my newbie day it tortured me seriously and i want to make it not to torture newbies of today.
Lets Begin:
Now you already have your data in the database, all you want is to search the data and callout related data following it,
In a file called search.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Search</title>
</head>
<body>
<!-- Creating a form for the search -->
<form action="" method="post">
<input type="text" name="keyword" placeholder="Enter keyword to search" /><br/>
<input type="submit" value="Search" /></form>
<?php
//Now the PHP code goes
//defining a variable before using it
if(isset($_POST['keyword']))
{
//now assigning to a variable
$word = $_POST['keyword'];
//if the user entered with an empty textbox
if(!$word)
{
//you can add you action
}
//If not found
elseif(mysql_num_rows(mysql_query("select * from your_table where your_column_ like'%$word%'"))<=0)
{
echo "Sorry, no results found";
}
else
{
?><center>Results</center><?php
//now query out your db
$query = mysql_query("select * from table_name where column_name like'%$word%'")or die(mysql_error());
while($row=mysql_fetch_array($query))
{
//fetch data in db
}
}
}
?>
</body></html>