2014-01-11 67 views
0

我想從我的數據庫中使用crud刪除所有行,這是我的刪除響應頁面。 我試着查詢刪除*,但沒有奏效,所以我手動輸入了這樣的。價值觀以未知的指標出現。任何人都可以幫忙,告訴我我做錯了什麼,或者給我一個更簡單的方法嗎?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> 
+1

爲什麼不使用'TRUNCATE TABLE studentanswers'?如果要選擇要刪除的特定行,則正確的語法是'DELETE FROM studentanswers WHERE column1 = value1' – Mave

+0

'delete * from'是無效的sql語法。刪除不接受字段列表,因爲您不能刪除單個字段 - 您只能刪除整行,這意味着所有字段都會被刪除。 '從表中刪除'是正確的語法 –

+0

@Mave會截斷刪除行或表?對不起,我是新手。 – taniakeira

回答

0

看起來你已經比這更難了。

作爲@Mave建議,你可以簡單地TRUNCATE TABLE studentanswers

假設你想刪除做到這一點,你是密切與delete *,但是這並不是說明它的正確方法:將這樣的伎倆

DELETE FROM STUDENTANSWERS 

如果你有某種預先配置的查詢輸入,其中包括一個WHERE的,你可以做

DELETE FROM STUDENTANSWERS WHERE 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);