我正在嘗試從包含例如襯衫的表格產品中獲取所有值。
在這種情況下,$thin 正在從搜索框“stxt”中獲取值。
這意味著如果 $thin = shirt,我想得到襯衫、T 恤等。
現在,我得到的只有襯衫,盡管我會在 $sql 陳述句中使用“LIKE”或“=”作為運算子.
$thin = $_POST['stxt'];
$thing = strtoupper($thin);
$sql = "select * from products where upper(productName) LIKE '$thing'";
uj5u.com熱心網友回復:
在您的查詢中,在變數之前和之后輸入您的 LIKE %。像這個“%$variable%”。如果您希望在變數之前或之后只有 n 個字符,請將 _ 符號放置 n 次。出于安全原因,請嘗試使用準備好的陳述句。
鏈接sql like:https ://sql.sh/cours/where/like
uj5u.com熱心網友回復:
你可以使用正則運算式運算子嗎?
$sql = "select * from products where productName regexp $thing";
uj5u.com熱心網友回復:
$thin = $_POST['stxt'];
$thing = strtoupper($thin);
$sql = "select * from products where upper(productName) LIKE '%$thing%'";
MSSQL 需要 % 通配符,其他 SQL 方言可能不同。或者,您可以執行 REPLACE(productName,'$thing','') 并將其長度與原始長度進行比較。無論哪種方式,除非您設定了全文索引,否則它將是全表掃描。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/436649.html
上一篇:如何在兩個專案之間迭代一個集合?
