dongpai1942 2017-11-16 13:56
浏览 40

PHP搜索引擎无法正常工作

I recently made a php function , but it isn't working like I want.
This is my code:

<div class="pageContent">
<?php

    getComments($conn);

    function getComments($conn){

        $searchFor = $_POST['keyword'];

        $sql = "SELECT adds.* FROM keywords JOIN adds on keywords.productID = adds.id and keywords.keyword LIKE '%".$searchFor."%'";
        $result = $conn->query($sql);
        while ($row = $result->fetch_assoc()) {

            echo "<div class='add'>
                <img src='uploads/".$row['imgURL']."'>
                <div>
                    <h1><a>".$row['name']."</a></h1>
                    <p>".$row['descr']."</p>
                </div>
            </div>";

        }
    }

?>
<br />

And the ($conn)

$conn = mysqli_connect("localhost", "root", "", "stp2");

if (!$conn) {

    die("Connection failed: ".mysqli_connect_error);

}

When there are normal 2 different results the function is just showing 2 times the same result.

I hope that you guys can help me.

  • 写回答

1条回答 默认 最新

  • duanli12176 2017-11-16 14:06
    关注

    If you are getting duplicate results you may want to group them by the ID of the 'adds' table using GROUP BY. This would get rid of multiple copies of the same row from that table

    评论

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大