doumei9589 2014-05-01 20:10
浏览 16
已采纳

显示相同内容的搜索结果[关闭]

I have a search bar and a sql database with 3 movies in

Name:Star Wars: Description: Contains the word group
Name:301: Description: Contains the word group
Name:destroyer: Description: Contains the word group

BUT when ever I search for the word "group"

I only get one result usually:

if i search for group star wars will appear 3 time.

also i know its vulnerable to sql injection but at the moment that is not an issue

here is my php code:

 if(!isset($_POST['search']))
 {
   header("Location:index.php");

 }

$search_sql="SELECT * FROM php_item WHERE Name LIKE '%".$_POST['search']."%' OR Description LIKE '%".$_POST['search']."%'";
$search_query = mysql_query($search_sql);
 if(mysql_num_rows($search_query)!=0)
 {

   $search_rs= mysql_fetch_assoc($search_query);
  }


 ?>


      </p>
      <p>&nbsp; Search Results</p>
      <?php

       if(mysql_num_rows($search_query) != 0){
          do{ ?>

          <p>
          <?php echo $search_rs['Name']; ?>

         <?php     }while($searchr_rs=mysql_fetch_assoc($search_query));

      } else {
        echo "No Results Found";  
      }
      ?>
  • 写回答

1条回答 默认 最新

  • dongyue9860 2014-05-01 20:25
    关注

    If this is your code, there is a typo in the while. It should be $search_rs=mysql_fetch_assoc($search_query). You have an extra 'r'.

    Good Luck!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)