mysql 쿼리에서 실행되는 검색 스크립트가 있습니다. display_name 또는 location이 쿼리와 비슷한 경우 일치하는 사용자를 데이터베이스에서 가져옵니다. 사용자 표시 이름에 대한 검색을 수행 할 때마다 다음과 같이 각 사용자에 대해 하나의 결과 만 얻습니다.mysql 쿼리를 1로 제한 하시겠습니까?
톰 = 1.tom davies 및 2.tom smith에 대해 2 개의 결과가 검색됩니다. 나는 그것이 같은 각 사용자에 대한 결과를 중복 위치 즉, 맨체스터를 검색 할 경우 어떤 이유로
:
톰 톰 톰 톰 데이비스 데이비스 을 데이비스 데이비스 톰 스미스 톰 스미스 톰 스미스 톰 스미스
누군가 내가이 작업을 중단하는 방법을 설명해 주실 수 있습니까? 검색 쿼리와 일치하는 각 사용자에 대해 동일한 사용자를 여러 번 표시하는 대신 하나의 결과 만 표시하도록합니다. 나는 ptb_users와 ptb_profiles에서 모두 select로 할 수 있다고 확신하지만 ptb_users에 포함될 'account type'과 'account_status'가 필요합니다.
감사
<?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_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_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."%'");
echo "<div class=\"results\">";
while($data_fetch=mysql_fetch_array($query_for_result))
{
echo "<div class=\"spacing\"><a href=\"profile.php?id={$data_fetch['user_id']}\">";
echo substr($data_fetch[$db_tb_atr_name], 0,160);
echo "</a></div>";
}
mysql_close();
}
?>
데이터베이스 테이블의 구조에 대한 정보를 제공해야합니다 ... –
왜이 :'ptb_users.account_type = \ "사용자 \"'... 왜 왜? 왜이'ptb_users.account_type = '사용자'? 내 오 마이 ... – CodeAngry