我已登录,我的身份证号是:mekha_id
我有2张桌子: 1)注册ID,用户名,... 2)sed_request rid,sender_id,reciever_id 我想做一个search.php
在注册(用户名)中搜索“mekhaname”之类的值..获取“mekhaname”的注册[id] ...转到sed_request表并检查sed_request中是否有一行包含mekha_id和registration [id ]在同一行......例如:
mekha_id是reciever_id abd注册[id]是sender_id ....或者mekha_id是sender_id,注册[id]是reciever_id ....如果是....我不想要这个用户(注册[ id])出现在我的搜索结果中的REGISTRATION表,,,,,,我希望你能帮我..... 这是我的代码
<?php
$sql = "SELECT * FROM `registration` where username LIKE '%$search%' and id!=$user_id;";
$result1 = mysql_query($sql) or die('Errant query2:'.$sql);
while($row = mysql_fetch_array($result1)) {
$data[] = $row;
}
?>
有什么帮助吗?
答案 0 :(得分:0)
您希望在&#34;注册&#34;上执行搜索并排除sed_request中的用户ID以及reciever_id或sender_id是当前用户ID的位置?
SELECT *
FROM `registration`
WHERE username LIKE '%$search%'
AND id != $user_id
AND id NOT IN (
SELECT sender_id
FROM sed_request
WHERE reciever_id = $user_id
)
AND id NOT IN (
SELECT reciever_id
FROM sed_request
WHERE sender_id = $user_id
)