我需要mysql数据库每个特定日期只包含20条记录,如果用户试图在已有20条记录的给定数据上输入更多数据...我希望程序拒绝该条目并提示用户另一个日期.i使用php mysql
这是我试过的
select count($hopeid)from clinics
Where $date > midnight today and $date < 1159pm tonight and $hopeid =(hopeid)
if results < 20 then
mysql_query("INSERT INTO clinics(hopeid, date, time, appttype, newonARV,newfile,txtname)
VALUES
('$hopeid','$date','$time','$appttype','$newonARV','$newfile','$txtname')") or die(mysql_errno());
else {
Echo"this date is full please choose another date";(mysql_errno();
}
答案 0 :(得分:0)
您可以在SQL查询中添加WHERE
条件,例如
检查this
执行查询后,使用mysql_affected_rows()
if(mysql_affected_rows()==1){
echo "Inserted..!";
}else if(mysql_affected_rows()==0){
echo "this date is full please choose another date";
}else{
echo "error:".mysql_error();
}
答案 1 :(得分:0)
选择日期调用之后Ajax查找此日期中的数字记录如果超过20条记录,那天显示一条消息已有20条记录在消息中并添加此新记录以将其作为日期+ 1等等它会转到下一个日期,以便用户轻松理解
答案 2 :(得分:0)
$result = mysql_fetch_array(mysql_query("select hopeid from clinics
WHERE " . $date . " BETWEEN '18/03/2011' AND '18/09/2011'"));
$result = sizeOf($result);
if ($result < 20){
mysql_query("INSERT INTO ... bla bla ...);
} else {
echo "this date is full please choose another date";
}