我的 php&mysql 搜索引擎中有一个错误。
这是一个简单的搜索引擎,但我决定通过将所需产品的图像添加到结果中来升级这个搜索引擎,所以我遇到的问题是,第一个产品的图像将是所有其他产品的图像.
这里的代码:
<?php
include ('Connections/connect.php');
// collect
if (isset($_POST['search'])) {
$searchq = $_POST['search'];
$searchq = preg_replace("#[^0-9a-z]#i", "", $searchq);
$query = mysql_query("SELECT * FROM tProduct WHERE sProduct LIKE '%$searchq%' OR sSearch LIKE '%$searchq%' OR sSort LIKE '%$searchq%'") or die("La Recherche est impossible");
$count = mysql_num_rows($query);
$result = mysql_query("SELECT * FROM tProduct WHERE sProduct LIKE '%$searchq%' OR sSearch LIKE '%$searchq%' OR sSort LIKE '%$searchq%'");
/*Afichage de L'image*/
$results = mysql_query("SELECT * FROM tProduct WHERE sProduct='$product'");
$row = mysql_fetch_row($result);
foreach($row as $results) {
$nom = $row[6];
}
$dir = "images/";
if ($row[6] == 0) {
$image_r = "images/none.png";
}
if ($row[6] != 0) {
if (file_exists($dir . $nom . ".JPEG")) {
$image_r.= $dir . $nom . ".JPEG";
}
else
if (file_exists($dir . $nom . ".jpg")) {
$image_r.= $dir . $nom . ".jpg";
}
else
if (file_exists($dir . $nom . ".jpeg")) {
$image_r.= $dir . $nom . ".jpeg";
}
}
if ($count == 0) {
$output = "Aucun Résultat Pour Cette Recherche!";
}
else {
while ($row = mysql_fetch_array($query)) {
$sProduct = $row['sProduct'];
$output.= '<div><ul><li><a target="_blanc" href="product.php?product=' . $sProduct . '" title="' . $sProduct . '"><img src="' . $image_r . '">' . $sProduct . '</a></li></ul></div>';
}
}
}
以上就是全部源代码了,希望对大家有所帮助!
并感谢 stackexchange 的所有成员。