【发布时间】:2015-03-29 11:43:03
【问题描述】:
我有这个 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";
}
从上面可以看出,它将首先选择备份表并遍历其中的所有记录,直到它从 id=$id 找到行基,然后比较 $itemname 是否在 itemname 列中匹配或$itemdesc 在 itemdesc 列中匹配,然后如果 itemname 或 itemdesc 中没有匹配项,则生成错误但似乎不起作用,为什么????任何想法、线索、建议、建议、帮助将不胜感激,谢谢!
【问题讨论】:
-
你试过 if (!$count_row >= 1) 吗?
-
我会不会尝试,但它会在我脸上留下很多错误!
-
我收到错误“试图获取非对象的属性
-
?????我的意思是这段代码! if (!$count_row>= 1) { //如果 itemname 或 item desc 中没有匹配项.. $error = $error + 1; echo "不匹配"; }
-
已解决,感谢您的帮助:)