我遇到了我的搜索查詢問題。我嘗試搜索基於用戶輸入的數據庫,並限制它們查看某些細節,但它不起作用。我究竟做錯了什麼?如何基於多個參數搜索
這裏是我的查詢:
if(isset($_GET['search_term']))
{
$search_term = $_GET['search_term'];
$ind = 'IND';
if(empty($search_term)){
echo '<div class="alert-warning" id="alert_message">Error: enter your query parameter.</div>';
}else{
$query = "SELECT * FROM [info].[dbo].[customer] WHERE cust_no LIKE '%$search_term' OR branch LIKE $search_term AND cust_type != 'BUS' AND cust_type != 'GRP' AND cust_type != 'MGM' AND cust_type != 'INT'" ;
$check = sqlsrv_query($conn, $query);
#checks if the search was made
if($check == false){
die(print_r(sqlsrv_errors(), true));
}
#checks if the search brought some row and if it is one only row
if(sqlsrv_has_rows($check) != 1){
echo '<div class="alert-warning" id="alert_message">Error: no data found for this query.</div>';
}
請寫多了,你想要什麼,你會得到什麼。可能這個'$ query =「SELECT * FROM [info]。[dbo]。[customer] WHERE(cust_no LIKE'%$ search_term'or branch LIKE $ search_term)AND cust_type!='BUS'AND cust_type!='GRP' AND cust_type!='MGM'AND cust_type!='INT'「;' –