我正在尝试使用crud删除数据库中的所有行,这是我的删除响应页面。 我尝试了查询删除*但这不起作用所以我手动输入它像这样。这些值将作为未识别的索引出现。任何人都可以帮忙,告诉我我做错了什么或者给出一个更简单的方法吗?
<?php
include "library.php";
include "database.php";
?>
<?php
//Get data from form
$faculty=$_POST["faculty"];
$date=$_POST["date"];
$modulecode=$_POST["modulecode"];
$moduletitle=$_POST["moduletitle"];
$school=$_POST["school"];
$modulebookcontent=$_POST["modulebookcontent"];
$moduleorganisation=$_POST["moduleorganisation"];
$lrcmaterials=$_POST["lrcmaterials"];
$moduledifficulty=$_POST["moduledifficulty"];
$modulesimilarity=$_POST["modulesimilarity"];
$contentinteresting=$_POST["contentinteresting"];
$previousknowledge=$_POST["previousknowledge"];
$understoodassessmentrequirements=$_POST["understoodassessmentrequirements"];
$assessmentmethod=$_POST["assessmentmethod"];
$markedwork=$_POST["markedwork"];
$ML_interestforsubject=$_POST["ML_interestforsubject"];
$ML_contentclear=$_POST["ML_contentclear"];
$ML_appropriateteachingpace=$_POST["ML_appropriateteachingpace"];
$ML_reachableforadvice=$_POST["ML_reachableforadvice"];
$ML_helpfulfeedback=$_POST["ML_helpfulfeedback"];
$L1_interestforsubject=$_POST["L1_interestforsubject"];
$L1_contentclear=$_POST["L1_contentclear"];
$L1_appropriateteachingpace=$_POST["L1_appropriateteachingpace"];
$L1_reachableforadvice=$_POST["L1_reachableforadvice"];
$L1_helpfulfeedback=$_POST["L1_helpfulfeedback"];
$L2_interestforsubject=$_POST["L2_interestforsubject"];
$L2_contentclear=$_POST["L2_contentclear"];
$L2_appropriateteachingpace=$_POST["L2_appropriateteachingpace"];
$L2_reachableforadvice=$_POST["L2_reachableforadvice"];
$L2_helpfulfeedback=$_POST["L2_helpfulfeedback"];
$moduleleader=$_POST["moduleleader"];
$lecturer1=$_POST["lecturer1"];
$lecturer2=$_POST["lecturer2"];
$indpstudy=$_POST["indpstudy"];
$attendance=$_POST["attendance"];
$bestfeatures=$_POST["bestfeatures"];
$improvemodule=$_POST["improvemodule"];
$queryString = "delete from studentanswers where faculty=".$faculty;
$queryString = "delete from studentanswers where date=".$date;
$queryString = "delete from studentanswers where modulecode=".$modulecode;
$queryString = "delete from studentanswers where moduletitle=".$moduletitle;
$queryString = "delete from studentanswers where school=".$school;
$queryString = "delete from studentanswers where modulebookcontent=".$modulebookcontent;
$queryString = "delete from studentanswers where moduleorganisation=".$moduleorganisation;
$queryString = "delete from studentanswers where lrcmaterials=".$lrcmaterials;
$queryString = "delete from studentanswers where moduledifficulty=".$moduledifficulty;
$queryString = "delete from studentanswers where modulesimilarity=".$modulesimilarity;
$queryString = "delete from studentanswers where contentinteresting=".$contentinteresting;
$queryString = "delete from studentanswers where previousknowledge=".$previousknowledge;
$queryString = "delete from studentanswers where understoodassessmentrequirements=".$understoodassessmentrequirements;
$queryString = "delete from studentanswers where assessmentmethod=".$assessmentmethod;
$queryString = "delete from studentanswers where markedwork=".$markedwork;
$queryString = "delete from studentanswers where ML_interestforsubject=".$ML_interestforsubject;
$queryString = "delete from studentanswers where ML_contentclear=".$ML_contentclear;
$queryString = "delete from studentanswers where ML_appropriateteachingpace=".$ML_appropriateteachingpace;
$queryString = "delete from studentanswers where ML_reachableforadvice=".$ML_reachableforadvice;
$queryString = "delete from studentanswers where ML_helpfulfeedback=".$ML_helpfulfeedback;
$queryString = "delete from studentanswers where L1_interestforsubject=".$L1_interestforsubject;
$queryString = "delete from studentanswers where L1_contentclear=".$L1_contentclear;
$queryString = "delete from studentanswers where L1_appropriateteachingpace=".$L1_appropriateteachingpace;
$queryString = "delete from studentanswers where L1_reachableforadvice=".$L1_reachableforadvice;
$queryString = "delete from studentanswers where L1_helpfulfeedback=".$L1_helpfulfeedback;
$queryString = "delete from studentanswers where L2_interestforsubject=".$L2_interestforsubject;
$queryString = "delete from studentanswers where L2_contentclear=".$L2_contentclear;
$queryString = "delete from studentanswers where L2_appropriateteachingpace=".$L2_appropriateteachingpace;
$queryString = "delete from studentanswers where L2_reachableforadvice=".$L2_reachableforadvice;
$queryString = "delete from studentanswers where L2_helpfulfeedback=".$L2_helpfulfeedback;
$queryString = "delete from studentanswers where moduleleader=".$moduleleader;
$queryString = "delete from studentanswers where lecturer1=".$lecturer1;
$queryString = "delete from studentanswers where lecturer2=".$lecturer2;
$queryString = "delete from studentanswers where indpstudy=".$indpstudy;
$queryString = "delete from studentanswers where attendance=".$attendance;
$queryString = "delete from studentanswers where bestfeatures=".$bestfeatures;
$queryString = "delete from studentanswers where improvemodule=".$improvemodule;
queryDatabase($queryString);
?>
<?php CRUDheader("Delete Student Answers"); ?>
<body>
<div id="main">
<div id="content">
<p>Student answers deleted</p>
</div>
</div><?php CRUDmain(); ?>
</body>
</html>
答案 0 :(得分:0)
看起来你已经比这更难了。
正如@Mave建议的那样,你可以简单地TRUNCATE TABLE studentanswers
。
假设您想要使用删除功能,那么您与delete *
关系密切,但这不是说明它的正确方法:
DELETE FROM STUDENTANSWERS
会做到这一点。
如果您有某种预先配置的查询输入,其中包含WHERE
您可以执行的操作
DELETE FROM STUDENTANSWERS WHERE 1=1
删除所有行。
答案 1 :(得分:0)
正在运行的唯一查询是在queryDatabase($ queryString)之前分配的最后一个查询。您可以在最后一个之前删除所有$ queryString =“delete ...”,并且您的代码将执行相同的操作。
从功能上讲,这是做同样的事情:
$queryString = "A"; //This does nothing because $queryString gets reset on the next line
$queryString = "B"; //This does nothing because $queryString gets reset on the next line
$queryString = "C"; //This does nothing because $queryString gets reset on the next line
$queryString = "delete from studentanswers where improvemodule=".$improvemodule;
queryDatabase($queryString);
回到你的问题。要删除所有行,您只需执行以下操作:
$queryString = "delete from studentanswers where 1=1;
queryDatabase($queryString);