我有一个发布Class Number值Ex的html表单。 150701-003
在我的php动作文件中,我想检查变量$ class_number是否已经在名为CLASS NO的MySql表列中。
{
"_id" : ObjectId("5549ec1575bd899c17ec5163"),
"messages" : [
{
"subject" : "diohvoidso",
"from" : ObjectId("5534a588a12ae5ac11dc6f6b"), //populated
"_id" : ObjectId("5549f42c75bd899c17ec5165"),
"created" : ISODate("2015-05-06T10:59:56.665Z"),
"read" : true,
"message" : "icdo ovdw iovhiwiohovhoihreiobv",
"participants" : [
ObjectId("5530b6208ab0478c2bd23292"),// populated
ObjectId("5534a588a12ae5ac11dc6f6b")
]
}
],
"participants" : [
ObjectId("5530b6208ab0478c2bd23292"), // logged in user
ObjectId("5534a588a12ae5ac11dc6f6b")
],
"__v" : 10
}
答案 0 :(得分:2)
尝试以下内容:
$result = mysqli_query($con, "SELECT * FROM Academy.COLUMNS
WHERE ClassNumber = '$class_number'");
if(mysqli_num_rows($result) == 0) {
// the number does not exist so do whatever you wish
} else {
// post an error message
}
答案 1 :(得分:1)
$check_class_number = mysqli_query($con, "SELECT * FROM Academy.COLUMNS
WHERE Class_Number = '$class_number' ");
if(count($check_class_number)>0){
echo "exists";
//do whatever you want to do
}
else{
echo "It does not exist.";
}
答案 2 :(得分:0)
使用mysqli_num_rows属性。
if( $check_class_number->num_rows > 0 ){
//yes
} else {
//no
}