我的資料庫
Name Title
Abu,Ali Red Shoes
Mia,Sarah Yellow shoes
我使用 LIKE '%$keyword%' 創建了一個搜索欄。當輸入關鍵字例如 Abu 或 Red shoes 時,我想要出現的結果是:
Abu
Red Shoes
Ali
Red Shoes
我只得到這樣的結果:
Abu,Ali
Red Shoes
如何在不分離的情況下在資料庫中分離結果...我需要將資料存盤在逗號值中
uj5u.com熱心網友回復:
在獲取 php 中的值后,您可以遍歷名稱并使用 php 的爆炸功能。請注意,此資料庫設定為失敗,將來很可能會導致問題和頭痛。最好將名稱分成單獨的行。但是,如果您真的不能以任何其他方式做到這一點,這就是您可以分離名稱的方法(我假設您將 SQL 結果放入一個名為 $result 的變數中)
if($result->num_rows > 0){
while($row = $result->fetch_assoc()){
$names = explode(",", $row["Name"]);
for($i = 0; $i < count($names); $i ){
echo "Name: " . $names[$i] . "Title: " . $row["Title"];
//In this for-loop you just iterate over the names and print them into
//the page. The first loop would be "Name: Abu Title: Red Shoes"
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/367614.html
下一篇:Azure應用服務托管內部技術
