我正在尝试从数据库中删除预订的方法。如何在循环中的条件之后编写DELETE语句。我在那里有我想要使用的声明,但我只是回应它。我不确定如何将声明付诸实施
function deleteBooking(){
$bData = mysql_query("SELECT * FROM booking_table ORDER BY Date_of_Booking ASC");
while($brecord = mysql_fetch_array($bData)){
$today = date('d-m-Y');
if($brecord['Date_of_Booking']>$today){
echo 'DELETE * FROM booking_table WHERE Date_of_Booking <'.$today.'';
}else{
echo 'not deleted';
}
}
}
答案 0 :(得分:0)
DELETE * FROM booking_table WHERE Date_of_Booking > NOW();
答案 1 :(得分:-1)
您正在回应查询。你需要执行它:
mysql_query("DELETE * FROM booking_table WHERE Date_of_Booking <'.$today.'");
编辑:忽略上述内容,未仔细阅读...
相反:
mysql_query("DELETE * FROM booking_table WHERE Date_of_Booking < now()");
此外,不推荐使用mysql_query,将来也会将其删除。因此我建议使用mysqli或PDO。
答案 2 :(得分:-1)
在你的情况之后做这件事
if($brecord['Date_of_Booking']>$today)
{
if(mysql_query("DELETE * FROM booking_table WHERE Date_of_Booking< now()")==true)
{
echo "delete successful";
}
else{
echo "delete failed";
}
}
注意:强>
简单$query = "SELECT name from Person WHERE Last_name = "John""
可能会导致潜在错误。
以这种方式编写将使语法错误更具可读性和安全性$query = "SELECT name from Person WHERE Last_name = 'John'"
手动使用双引号和单引号