0
我的查詢有什麼問題?我想要發生的是,當我按順序搜索一個數字時,輸出將是我在搜索欄中爲訂單ID輸入的內容。發生的事情知道的是,當我輸入一個數字時,所有的「接受」和「分派」都包括在內。如何正確搜索php
這是我現在的代碼。
<?php
session_start();
$order_id = $_SESSION['order_id'];
if (!isset($_SESSION['user_id'])) {
header("Location: index.php");
}
$_SESSION['navMenu'] = "order";
ini_set('display_errors', 'On');
require_once 'includes/database.php';
include_once 'system_menu.php';
include_once 'ordermodal.php';
include_once 'ordermodal2.php';
$sql2 = "SELECT * FROM cart_tbl";
date_default_timezone_set("Asia/Hong_Kong");
$sql = "SELECT * FROM order_tbl WHERE order_status = 'Accepted' or order_status = 'Dispatched' or order_status = 'Pending'";
/*** * SET UP COMBO BOX FOR SEARCH */
$comboBox = isset($_REQUEST['comboBoxVal']) ? trim($_REQUEST['comboBoxVal']) : '';
$search_by = isset($_REQUEST['search_by']) ? addslashes($_REQUEST['search_by']) : 0;
$orders= null;
if ($comboBox != '') {
switch ($search_by) {
case 1://Order ID
$sql .= " AND order_id LIKE '%{$comboBox}%' ";
break;
case 2://Driver Number
$sql .= " AND driver_number LIKE '%{$comboBox}%' ";
break;
}
}
$carts = mysqli_query(connection2(), $sql2);
$orders = mysqli_query(connection2(), $sql);
$search_filters = array(1 => 'Order ID', 2 => 'Driver Number');