0

我在让我的查询排除我的“软删除”列时遇到问题 我已将我的代码附在下面关于让它工作的任何提示?它显示具有deleted= 1 的行,我只需要它来显示 0

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

$query_for_result=mysql_query("SELECT * FROM Assets WHERE 
`Badge` like '%".$query."%' or 
`Status` like '%".$query."%' or 
`First Name` like '%".$query."%' or 
`Last Name` like '%".$query."%' or 
`Service Tag` like '%".$query."%' or 
`Asset Tag` like '%".$query."%' and
`deleted` = '0' ")or die(mysql_error());



if(mysql_num_rows($query_for_result1)==0){

}

while($data_fetch=mysql_fetch_array($query_for_result))
{

echo '<h3>';    
echo "<a href=\"modify.php?id=" . $data_fetch['id'] . "\">" . $data_fetch['First Name']  . ' ' . $data_fetch['Last Name'] . "</a>";
echo '<br/><b>Badge:</b> '. $data_fetch['Badge'];
echo '<br/> <b>Service Tag:</b> '. $data_fetch['Service Tag'];
echo ' <b>Asset Tag:</b> '. $data_fetch['Asset Tag'];
echo '<br/> <b>Status:</b> '. $data_fetch['Status'];
echo '<br/><b>Employee Status: </b>';
    if( $data_fetch['Employee Status'] == 'Active' ){
echo '<font color="#32CD32">' . $data_fetch['Employee Status'] . '</font>';
    }
elseif( $data_fetch['Employee Status'] == 'Terminated' ){
echo '<font color="red">' . $data_fetch['Employee Status'] . '</font>';}
echo '<br/> <b>Last Modified:</b> '. $data_fetch['Last Modified'];
echo "<span> </span>";
echo '</h3>';
echo '<br/><p>' ; 

}
4

1 回答 1

1

所有条件句都在同一范围内。这意味着,只要您遇到第一个为真的条件,整个 where 子句就为真。您需要将 OR 子句放在括号中。

WHERE 
(
`Badge` like '%".$query."%' or 
`Status` like '%".$query."%' or 
`First Name` like '%".$query."%' or 
`Last Name` like '%".$query."%' or 
`Service Tag` like '%".$query."%' or 
`Asset Tag` like '%".$query."%'
)
and `deleted` = '0'
于 2012-07-25T17:10:15.593 回答