php mysql搜索只给出1个结果

时间:2013-10-12 11:58:15

标签: php mysql search

我编码了一个搜索功能,但我总是得到1个结果!

有谁知道问题出在哪里?

<?PHP
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
      $sqlCmdSearch="SELECT * FROM name.name WHERE title LIKE '%".mysql_real_escape_string($_POST['search'])."%'";
      $getSearch=mysql_query($sqlCmdSearch,$sqlHp);
          while($getSearch = mysql_fetch_array($getSearch)) {
    echo'<div id="main_item2">';
    echo'   <div class="main_image">';
    echo'   <a href="index.php?s=items&id='.$getSearch["id"].'"><img src="www/img/thumbs/'.$getSearch["image"].'"></a>';
    echo'   </div>';
    echo'   <div class="title_list">';
    echo'   <a href="index.php?s=items&id='.$getSearch["id"].'">'.$getSearch["title"].'</a>';
    echo'   </div>';
    echo'   <div class="description_list"> ';
    echo'   <p>'.$getSearch["description"].'</p>';
    echo'   </div>';
    echo'   <div class="button_list">';
    echo'   <p>Price: '.$getSearch["item_price"] .' '.$getSearch["currency"].'</p>';
    echo'   <span style="padding-left:15px;"><a href="index.php?s=items&id='.$getSearch["id"].'" class="button">Watch Item</a></span>';
    echo'   </div>';
    echo'</div>';
}
}
else{
echo '<p>Search failed please try again.</p>';
}
?>

我已经尝试了一切,但没有任何帮助..

1 个答案:

答案 0 :(得分:2)

您正在覆盖您的mysql结果变量

所以请替换以下代码:

$getSearch=mysql_query($sqlCmdSearch,$sqlHp);
      while($getSearch = mysql_fetch_array($getSearch)) {

这个:

$getSearch_set=mysql_query($sqlCmdSearch,$sqlHp);
      while($getSearch = mysql_fetch_array($getSearch_set)) {