[英]use mysql_num_rows for two tables
I have a problem with mysql duplication. 我对mysql复制有问题。 I have two tables name as student and temp_student. 我有两个表,分别是student和temp_student。 Both tables have same fields except for temp_student, i've add studentStatus and statusNote. 除了temp_student之外,两个表都具有相同的字段,我添加了studentStatus和statusNote。 The problem is, when I use mysql_num_rows
for any tables to search the duplication data, such as student name, it echos the duplication error. 问题是,当我对任何表使用mysql_num_rows
搜索重复数据(例如学生姓名)时,都会产生重复错误。 But when i use mysql_num_rows
for both tables, and i inserted the same student name into both table, the data still duplicate. 但是,当我在两个表中都使用mysql_num_rows
,并且在两个表中都插入了相同的学生名时,数据仍然重复。 Here is my code: 这是我的代码:
$name = $_POST['name'];
$checkName = mysql_query("select *from student where name = '$name'");
$checkNameTemp = mysql_query("select * from temp_student where name = '$name");
//$check = $checkName + $checkNameTemp;
if(mysql_num_rows($checkName) && mysql_num_rows($checkNameTemp) > 0){
echo "Duplicate Data";
}
else{
$insertStudentQuery = mysql_query("INSERT INTO student(name,noic, createDate) VALUES('$name','$Ic', NOW())");
$insertStudentQueryTemporary = mysql_query("INSERT INTO temp_student(name,noic, createDate) VALUES('$name','$Ic', NOW())");
}
Your IF will only hit when both have more than 0 rows. 仅当两者的行数都超过0时,您的IF才会命中。 Not if any has. 如果没有的话。 Use || 使用|| to check for any non zero rows. 检查任何非零行。
if(mysql_num_rows($checkName) || mysql_num_rows($checkNameTemp)){
echo "Duplicate Data";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.