如何在一个查询中创建OR语句?

时间:2012-05-06 19:18:57

标签: php mysql

如何对此类内容进行OR查询?

//Query
$sql = "select `Friend_status` from `friendship_box` where 
`system_id` = '$sid' and `friend_id` = '$friendis' OR 
`system_id='$friendis' and `friend_id` = '$sid'";
$query = mysql_query($sql) or die ("Error: ".mysql_error());

while ($row = mysql_fetch_array($query)){
$activity = htmlspecialchars($row['Friend_status']);
}
mysql_free_result($query);

1 个答案:

答案 0 :(得分:2)

select `Friend_status` from `friendship_box` 
where (`system_id` = '$sid' and `friend_id` = '$friendis')
OR (`system_id`='$friendis' and `friend_id` = '$sid')

你错过了`

...OR (`system_id` <--