0

我有一个搜索引擎,但问题是搜索引擎不显示搜索结果,与数据库的连接是正确的,代码如下:

PHP:

if (isset($_POST['search'])) {
$searchq = $_POST['search'];
$searchq = preg_replace("#[^0-9a-z]#i", "", $searchq);
$query = mysql_query("SELECT * FROM tReference WHERE sReference LIKE '%$searchq%' OR sSearch LIKE '%$searchq%' OR sSort LIKE '%$searchq%'") or die("La Recherche est impossible");
$count = mysql_num_rows($query);


if ($count == 0) {
    $output = "Aucun Résultat Pour Cette Recherche!";
              //English Trans : No results have been Found!

}
else 
{
        $sReference = $count['sReference'];
        $output.= '<div><ul><li><a target="_blanc" href="refrences.php?reference=' . $sReference . '" title="' . $sReference . '">' . $sReference . '</a></li></ul></div>';
}

}

HTML:

<div id="searchd">
<div class="searchc">
<form action="reference.php" method="post">
<input type="text" name="search" palceholder="Recherhcer...">
<input type="submit" Value="Ok">
<div class="clear"></div>
</form>
</div>
<div id="output">
<?php echo ($output); ?>
</div>
</div>

并提前感谢所有人!

4

3 回答 3

1

您实际上并没有处理查询的结果。您必须从返回的结果集中获取每一行,然后使用 html 输出中返回的字段。

尝试这个:-

if (isset($_POST['search'])) {
    $searchq = $_POST['search'];
    $searchq = preg_replace("#[^0-9a-z]#i", "", $searchq);
    $query = mysql_query(
        "SELECT * FROM tReference 
         WHERE sReference LIKE '%$searchq%' OR 
               sSearch LIKE '%$searchq%' OR 
               sSort LIKE '%$searchq%'") or die("La Recherche est impossible");

    if (mysql_num_rows($query) == 0) {
        $output = "Aucun Résultat Pour Cette Recherche!";
              //English Trans : No results have been Found!
    } else {

        $output .= '<div><ul>';
        while ( $row = mysql_fetch_object($query) ) {
            $output .= '<li>';
            $output .= '<a target="_blanc" href="refrences.php?reference=' . $row->sReference . '" '; 
            $output .= '" title="' . $row->sReference . '">' . $row->sReference . '</a>';
            $output .= '</li>';
        }
        $output .= '</ul></div>';
    }

}
于 2013-08-19T23:31:29.203 回答
0

已经完成了,谢谢大家,这是解决方案:

if (isset($_POST['search'])) {
$searchq = $_POST['search'];
$searchq = preg_replace("#[^0-9a-z]#i", "", $searchq);
$query = mysql_query(
"SELECT * FROM tReference 
WHERE sReference LIKE '%$searchq%' OR 
   sSearch LIKE '%$searchq%' OR 
   sSort LIKE '%$searchq%'") or die("La Recherche est impossible");

if (mysql_num_rows($query) == 0) {
$output = "Aucun Résultat Pour Cette Recherche!";
} else {

$output .= '<div><ul>';
while ( $row = mysql_fetch_assoc($query) ) {

$sReference = $row['sReference'];

$output .= '<li>';
$output .= '<a target="_blanc" href="refrences.php?reference="' . $sReference . '" '; 
$output .= '" title="' . $sReference . '">' . $sReference . '</a>';
$output .= '</li>';
}
$output .= '</ul></div>';
}

}

感谢@RiggsFolly,感谢你们所有人。

于 2013-08-19T23:49:17.587 回答
0

你的代码没有意义。首先,我建议您在单独的安全页面上使用面向对象的 PHP。那么你的代码应该看起来更像:

//secure.php
<?php
 function db(){
   return new mysqli('host', 'user', 'password', 'database');
 }
?>

//reference.php
include 'secure.php'; $output = '';
if(isset($_POST['sub'])){
  $db = db(); $searchq = $_POST['search'];
  // What is this for? --->>> $searchq = preg_replace('/[^0-9a-z]/i', "", $searchq);
   $query = $db->query("SELECT * FROM tReference WHERE sReference LIKE '%$searchq%' || sSearch LIKE '%$searchq%' || sSort LIKE '%$searchq%'");
   if($query->num_rows < 1){
     die('Aucun Résultat Pour Cette Recherche!');
   }
   else{
    while($row = $query->fetch_assoc()){
      $sref = $row['sReference'];
      $output.= "<li><a target='_blank' href='refrences.php?reference=$sref' title='$sref '>$sref</a></li>";
   }
   $query->free(); $db->close();
}
<div id='searchd'>
  <div class='searchc'>
    <form action='reference.php' method='post'>
      <input type='text' name='search' placeholder='Recherhcer...' />
      <input type='submit' value='Ok' name='sub' />
      <div class='clear'></div>
    </form>
  </div>
  <ul id='output'><?php echo $output; ?></ul>
</div>
于 2013-08-19T23:50:11.973 回答