السلام عليكم
عملت محرك بحث ويشتغل بس مشكلته انه نتيجه البحث تظهر مو مرتبه يعني ماتظهر بنفس الجدول
وهذي الصورتين
قبل البحث:

بعد البحث:

انا حابب انه يظهر البحث بنفس الجدول مثلا لو بحث عن ورد لونه بنك تختفي الوردات الثانيات وتظهر بس الوردات الي فيها بينك
<?php
session_start(); //starting the session
include("connectdb1.php"); //Connect to database through include file
?>
<!------------------------------- Shop Form In HTML------------------------------->
<!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>
<title> Rosy Shop - Homepage</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<center>
<form action='./searchitem.php' method='get'>
<input type='text' name='keywords' size='20' value='' />
<input type='submit' size='20' value='Search' />
</form>
</center>
<h1> Rosy Online Shop </h1>
<br />
<br />
<a href="shopcode.txt">View Code</a>
<table border="1">
<?php
$sql = "SELECT * FROM products;"; //get everything from products table
$result = mysql_query($sql);
echo("<center><table border = \"2\">"); //set up a table to show the result
echo("<tr><td><b><p>Product Name</b></p></td><td><b><p>Product Image</b></p></td><td><b><p>Description</b></p></td><td><b><p>Price</b></p><td><b><p>Basket</b></p></td></tr>");
while(list($pid, $pname, $pimage, $pdescription, $pprice) = mysql_fetch_row($result)) { //loop round each record
echo "<tr>";
echo "<td>$pname</td>"; //display product name from products table in SQL database
echo("<td> <img src ='" .$pimage . ".png' alt= 'flower' /></td>"); //display product image from products table in SQL database
echo "<td>$pdescription</td>"; //display product description from products table in SQL database
echo "<td>$pprice</td>"; //display product price from products table in SQL database
echo "<td><a href=\"shoppingbasket.php?action=addItem&ID=$pid\">Add To Basket</a></td>"; //link to shoppingcart.php when user click on Add to basket link
echo "</tr>";
}
?>
<?php
//*********************************** Search Code In PHP *****************************************//
if (isset($_GET['keywords']) && trim($_GET['keywords']) != '') { //get the search varible from $keywords
$keywords = trim($_GET['keywords']); //trim whitespace from $keywords
$terms = explode(' ', $keywords); // break the string $keywords into an array which will display the matching results from SQL database
$query = "SELECT * FROM products WHERE "; // build SQL query which which will select everything from products table
$i = 1;
foreach ($terms as $every) { // Build SQL query for each keyword entered in the input field
if ($i == 1)
$query .= "pname LIKE '%$every%' OR pdescription LIKE '%$every%'"; // product name or product description is matching with the string
else
$query .= " OR pname LIKE '%$every%' OR pdescription LIKE '%$every%'";
$i++; // increment $i by 1
}
$result = mysql_query($query) or die('Could not execute query'); //get results
$numrows = mysql_num_rows($result);
if ($numrows > 0) {
while ($row = mysql_fetch_assoc($result)) { //display the results returned
$pid = $row['pid'];
$pname = $row['pname'];
$pimage = $row['pimage'];
$pdescription = $row['pdescription'];
$pprice = $row['pprice'];
echo "<p><b>$pname</b><br/></p>"; //display product name of what the user searched for on the screen with break before each record
echo "<img src ='".$pimage.".png' alt= '' style='top:0px; left:0px;' />"; //display product image on the screen
echo "<p>$pdescription<br/></p>"; //display product descrpition of what the user searched for on the screen with break before each record
echo "<p>$pprice<br/></p>"; //display product price of what the user searched for on the screen with break before each record
}
} else
echo "<h1>Sorry, no results found for \"<b>$keywords</b>\" please try another search</h1>"; //display this message if there isn't any results that matching what the user searched for
mysql_close(); // close connection to SQL database
}
?>
</body>
</html>



