我在查询时排除我的“软删除”列时遇到问题我已将我的代码附加到下面的任何有关此功能的提示吗?它显示了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>' ;
}
答案 0 :(得分: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'