Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PHP将搜索结果链接到MySQL中的项目_Php_Mysql_Search_Hyperlink - Fatal编程技术网

使用PHP将搜索结果链接到MySQL中的项目

使用PHP将搜索结果链接到MySQL中的项目,php,mysql,search,hyperlink,Php,Mysql,Search,Hyperlink,我有两个文件返回错误,“search.php”和“advert.php?=$id”。我需要将我的结果链接到一个超链接,将用户发送到特定的“广告页面”。结果会是一组广告,有人知道我哪里会出错,如果可能的话,如何修复错误吗?在我看来,他们还不错 谢谢 search.php <?php include("connect.php"); //if user didn't get here by searching send back to home page if

我有两个文件返回错误,“search.php”和“advert.php?=$id”。我需要将我的结果链接到一个超链接,将用户发送到特定的“广告页面”。结果会是一组广告,有人知道我哪里会出错,如果可能的话,如何修复错误吗?在我看来,他们还不错

谢谢

search.php

    <?php

    include("connect.php");

    //if user didn't get here by searching send back to home page
    if (!isset($_POST['search']))   {

        header("Location: index.php");


    }

//fix the query
//query the db using connection and sql query
$query = mysqli_query($link, "SELECT advert.advert_id, advert.advert_title, advert.price,  FROM advert WHERE advert.advert_title, advert.make, advert.model LIKE '%".$_POST['search']."%'");    

if (mysqli_num_rows($query)!=0) {

    //fetch the text fields
    $rs = mysqli_fetch_assoc($query);

}



$query2 = mysqli_query($link,  media.FILE_NAME);

if (mysqli_num_rows($query2)!=0)    {

    //fetch the image file name fields
    $rs_ = mysqli_fetch_assoc($query2);

}


?>

<!-- for the results section on the website -->

<h3> Search Results </h3>

<?php

    if (mysqli_num_rows($query)!=0) {
        do { ?>

        <!--place in div for advert title -->
        <div class= "title_of_advert">
        <?php
        $title= $rs['advert_title'];    
        $advert=$rs['$advert_id'];
        echo "<a href=\"advert.php?data=$advert\">
        $title</a>"; //display advert title with link to advert page

        ?> 
        </div>

        <!-- place in div for advert price  -->
        <div class= "price_of_advert">
        <?php echo $rs['price']; ?> 
        </div>

        <!-- place in display the thumbnail -->
        <div class= "thumbnail_of_ad" >
        <?php 

        $filepath = "http://localhost/projects/FYP/user_data/";
        $src= $filepath.$rs_['FILE_NAME'];

        echo "<img src=\".$src."\"/>"; 

        ?> 
        </div> 

<?php           } while($rs=mysqli_fetch_assoc($query));

    } else {

        echo "No Results have been found";

    }

?>

在您的查询中,您有一个额外的
之前,并且
where
子句的条件是错误的:

$query = mysqli_query($link, "SELECT advert.advert_id, advert.advert_title, advert.price,  FROM advert WHERE advert.advert_title, advert.make, advert.model LIKE '%".$_POST['search']."%'");
应该是:

$query = mysqli_query($link, "SELECT advert.advert_id, advert.advert_title, advert.price  FROM advert WHERE advert.advert_title LIKE '%".$_POST['search']."%'" OR advert.make LIKE '%".$_POST['search']."%'" OR advert.model LIKE '%".$_POST['search']."%'");   
同样在第二部分中,在您将
=
%
一起使用的
where
子句中,它应该与
类似,如下所示:

$query = mysqli_query($link, "SELECT * FROM advert WHERE advert.advert_id LIKE '%".$id."%'");

您可以随时回显您的查询,并将其作为MySQL客户端中的独立查询运行,查看您的查询是否正常工作并返回任何结果。

感谢您的帮助,我非常感谢您在这些查询中遇到的问题。下面一点呢,我的链接有问题吗?你不能用这个:echo“$rs['advert_title'”;尝试以下任一选项:echo“{$rs['advert_title']}”;或“回声”$rs[“广告标题”]。"";
$query = mysqli_query($link, "SELECT * FROM advert WHERE advert.advert_id LIKE '%".$id."%'");