0

我编写了一个搜索功能,但我总是只得到 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>';
}
?>

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

4

1 回答 1

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)) {
于 2013-10-12T12:01:21.813 回答