0

我制作了这个定位用户的小搜索脚本,并试图使搜索结果可点击。我正在尝试将 url 指向个人资料 ID,但运气不佳。基本上每个配置文件的 id 为 1,2,3,4 等,我需要找到一种方法使搜索结果在单击时与配置文件 id 相对应。有人可以帮忙吗?

<form method="get" action="">
<input type="text" name="query" class="search" placeholder="Search Name/Location" style="width:120px;"/>
<input type="image" src="../PTB1/assets/img/icons/loginarrow1.png" class="searchbutton" name="submit" value="Start Search" />
</form>

<?php
//PHP CODE STARTS HERE

if(isset($_GET['submit'])){

// Change the fields below as per the requirements
$db_host="localhost";
$db_username="root";
$db_password="";
$db_name="database";
$db_tb_name="ptb_profiles";
$db_tb_atr_name="display_name";

//Now we are going to write a script that will do search task
// leave the below fields as it is except while loop, which will display results on screen

mysql_connect("$db_host","$db_username","$db_password");
mysql_select_db("$db_name");

$query=mysql_real_escape_string($_GET['query']);

$query_for_result=mysql_query("SELECT * FROM `$db_tb_name` 
        WHERE display_name like '%".$query."%' 
        OR location LIKE '%".$query."%' OR orientation LIKE '%".$query."%'");
echo "<div class=\"results\">";
while($data_fetch=mysql_fetch_array($query_for_result))
{
    echo "<div class=\"spacing\"><a href=\"profile.php?id={$profile['user_id']}\">";
    echo substr($data_fetch[$db_tb_atr_name], 0,160);
    echo "</a></div>";

}


mysql_close();
}

?>

我试图使用这个功能,但它只是列出了所有用户,基本上不是我想要的。

function get_searched_users() {
            global $connection;
            $query = "SELECT *
                        FROM ptb_users, ptb_profiles
                        WHERE ptb_users.account_type = \"user\"
                        AND ptb_users.account_status = \"Active\"
                        AND ptb_profiles.user_id = ptb_users.id
                        AND display_name like '%".$query."%' 
        OR location LIKE '%".$query."%' OR age LIKE '%".$query."%'";
            $search_set = mysql_query($query, $connection);
            confirm_query($search_set);
            return $search_set;

    }
4

1 回答 1

0

尝试这个:

while ($data_fetch=mysql_fetch_array($query_for_result))
{
    echo "<div class=\"spacing\">";
    echo "<a href=\"profile.php?id={$data_fetch['user_id']}\">";
    echo substr($data_fetch[$db_tb_atr_name], 0,160);
    echo "</a></div>";
}

实际上,您需要使用该$data_fetch变量并且您正在使用该变量$profile

于 2012-10-31T17:08:37.727 回答