检查是否有来自指定数据的匹配记录库
check if theres a match record base from data specified
我有这个 mysql 语法。
//select backup table and loop through all records until it find the row base from the id and then compare if the $itemname is match in itemname column or $itemdesc is match in itemdesc column
$sql2="SELECT * FROM backup WHERE id='$id' AND itemname='$itemname' OR itemdesc='$itemdesc'";
$result2 = mysqli_query($this->db,$sql2);
$user_data = mysqli_fetch_array($result2);
$count_row = $result2->num_rows;
if (!$count_row == 1) {
//if theres no match either in the itemname or item desc..
$error = $error + 1;
echo "no match";
}
从上面可以看出,它会先select备份table,然后循环遍历里面的所有记录,直到找到id=$id的行基,然后比较如果 $itemname 在 itemname 列中匹配或 $itemdesc 在 itemdesc 列中匹配,然后如果在 itemname 或 itemdesc 中都不匹配,则生成并出错但似乎不起作用,为什么????任何想法,线索,建议,建议,帮助将不胜感激,谢谢!
删除 $user_data 因为它没有用处并将 sql 语法更改为
$sql2="
SELECT * FROM backup
WHERE id='$id'
AND itemname='$itemname'
AND itemdesc='$itemdesc'
";
因为您想比较 itemname 或 itemdesc。
我有这个 mysql 语法。
//select backup table and loop through all records until it find the row base from the id and then compare if the $itemname is match in itemname column or $itemdesc is match in itemdesc column
$sql2="SELECT * FROM backup WHERE id='$id' AND itemname='$itemname' OR itemdesc='$itemdesc'";
$result2 = mysqli_query($this->db,$sql2);
$user_data = mysqli_fetch_array($result2);
$count_row = $result2->num_rows;
if (!$count_row == 1) {
//if theres no match either in the itemname or item desc..
$error = $error + 1;
echo "no match";
}
从上面可以看出,它会先select备份table,然后循环遍历里面的所有记录,直到找到id=$id的行基,然后比较如果 $itemname 在 itemname 列中匹配或 $itemdesc 在 itemdesc 列中匹配,然后如果在 itemname 或 itemdesc 中都不匹配,则生成并出错但似乎不起作用,为什么????任何想法,线索,建议,建议,帮助将不胜感激,谢谢!
删除 $user_data 因为它没有用处并将 sql 语法更改为
$sql2="
SELECT * FROM backup
WHERE id='$id'
AND itemname='$itemname'
AND itemdesc='$itemdesc'
";
因为您想比较 itemname 或 itemdesc。