我正在使用搜索脚本。它按名称或位置查找用户。我正在尝试将图像添加到搜索中找到的每个用户。但是当我这样做时,即使不在搜索中也会列出每个用户的图像,并将搜索到的名称和图像重复十几次,如下所示:
image1.jp用户:迈克尔 image1.jp用户:迈克尔 image1.jp用户:迈克尔 image1.jp用户:迈克尔 image1.jp用户:迈克尔 image1.jp用户:michael
image2.jp用户:eric image2.jp用户:eric image2.jp用户:eric image2.jp用户:eric image2.jp用户:eric image2.jp用户:eric
等等。有人可以让我知道如何限制它只显示搜索中出现的每个用户配置文件的一个图像,而不会将显示在搜索中的用户显然限制为1?
继承我的代码:
<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="playtime";
$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 ptb_profiles
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))
{
$search_set = get_searched_escorts();
while ($searched = mysql_fetch_array($search_set)) {
echo "<div class=\"spacing\"><a href=\"profile.php?id={$data_fetch['user_id']}\" class=\"search\">";
echo "<img width=80px height= 80px src=\"data/photos/{$searched['id']}/_default.jpg\" class=\"boxgrid\"/> ";
echo substr($data_fetch[$db_tb_atr_name], 0,160);
echo "</a></div>";
}
}
mysql_close();
}
?>
谢谢。
答案 0 :(得分:0)
尝试放置GROUP BY user_id
$ query_for_result =请求mysql_query(“
SELECT *
来自ptb_profiles
显示名称如'%'。$ query。“%'
OR location LIKE'%“。$ query。”%'或orientation LIKE'%“。$ query。”%'
GROUP BY user_id“);