使用php / mysql从多个表中删除记录的正确方法是什么?

时间:2016-06-13 06:18:03

标签: php mysql mysqli

我正在使用以下方法,但我想通过使用单个查询来改进它...

view.selectedProvince = view.provinces[0];

这段代码工作正常,但是每当我用单行编写查询时,它只删除前两张表中的记录,然后不要......

$sql="DELETE FROM expense";
$sql1="DELETE FROM invoice";
$sql2="DELETE FROM cat";
$sql3="DELETE FROM conf";
$sql4="DELETE FROM patient";
$sql5="DELETE FROM prv";
$sql7="DELETE FROM test_invoice";
$sql8="DELETE FROM test_style";

 if (mysql_query($sql) && mysql_query($sql1) && mysql_query($sql2)&&    mysql_query($sql3)&& mysql_query($sql4)&& mysql_query($sql5)&& mysql_query($sql7)&& mysql_query($sql8)) {
header("location:backup_page.php");

} else {
echo "Error deleting record: " . mysqli_error($conn);
 }
}

2 个答案:

答案 0 :(得分:0)

你想要这个吗?

'.toggle'

答案 1 :(得分:-1)

将所有表名放在一个数组中,然后使用循环遍历所有并编写查询,这样你就需要少写并做更多...

java.sql.SQLException: After end of result set
at com.mysql.jdbc.ResultSet.checkRowPos(ResultSet.java:4353)
at com.mysql.jdbc.ResultSet.getStringInternal(ResultSet.java:2137)
at com.mysql.jdbc.ResultSet.getString(ResultSet.java:2132)
at com.mysql.jdbc.ResultSet.getString(ResultSet.java:2250)
at WebArtifactListener$2.run(WebArtifactListener.java:166)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

休息你可以管理...希望它会有所帮助...