[英]PHP mysql usage of FIND IN SET to search column values
這是我的db表“課程”
當您添加多個年齡組和國家/地區的數據時,我想檢查它是否已存在於db上
示例名稱不能與同一國家+年齡組合重復
如果name =“sw”,則用戶無法再次為2年級添加國家1或4或5或3
$age1 = explode(",", $age);
$country1 = explode(",", $country);
foreach($age1 as $ages)
{
foreach($country1 as $country2)
{
$where = "find_in_set( $country2,`country`) <> 0 AND find_in_set( $ages,`age`) <> 0 AND `name` = '" . $name . "'";
}
}
請檢查以下結果......
var_dump($age);exit;
string '2,1' (length=3)
var_dump($country);exit;
string '1,4,2,3' (length=7)
var_dump$country1
array (size=2)
0 => string '2' (length=1)
1 => string '1' (length=1)
后續代碼var_dump($ AGE-1);退出;
array (size=4)
0 => string '1' (length=1)
1 => string '4' (length=1)
2 => string '2' (length=1)
3 => string '3' (length=1)
這里你用了兩次相同變量的$,這里沒有使用它。
$where = $country." IN country AND ".$age." IN age";
$this->db->select("music_lessons","*",$where);
$res = $this->db->getResult();
返回結果行數
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.