このソリューションを見つけるのを手伝ってください.2Mの学生テスト結果レコードのような非常に大きなデータのレコードを処理しています.すべてのレコードは1つのテーブルに保存されていました.私がする必要があるのは、このレコードを2つの異なるテーブルに分けることです.もう1つは不合格の学生用です。このレコードを分離した後、元のレコードをソーステーブルから削除する必要があります。このコードを実行するたびに、完了するまでに数時間以上かかります。誰かが解決策を見つけるのを手伝ってくれるならありがとう。
サンプルコードは次のとおりです。
<?php ob_start(); ?>
<?php
function spread($classselect,$subjectselect)
{include "connectdb.php";
//movepass
$selectpass = mysql_query("SELECT * FROM testresultAUG2012 WHERE actualmonth='AUG' AND testresult = 'PASS' AND classname = '$classselect' AND educationsubject = $subjectselect;",$conn);
$totalpass = mysql_num_rows($selectpass);
$pass=0;
while($pass<$totalpass)
{
$name=mysql_result($selectpass, $pass, "Studentname");
$subject=mysql_result($selectpass, $pass, "Subject");
$testbatch=mysql_result($selectpass, $pass, "testbatch");
$classname=mysql_result($selectpass, $pass, "class");
$lecturer=mysql_result($selectpass, $pass, "lecturer");
$date=mysql_result($selectpass, $pass, "date");
$month=mysql_result($selectpass, $pass, "month");
$time=mysql_result($selectpass, $pass, "time");
$state=mysql_result($selectpass, $pass, "result");
//count total pass subject and add 1
$totalpass = mysql_query("SELECT * FROM Student WHERE Studentname = '$name';",$conn);
$only = mysql_fetch_array($theone);
$currentpass = $only['totalpass'];
$newpass = $currentpass + 1;
mysql_query("UPDATE Student SET totalpass = $newpass WHERE Studentname = '$name';",$conn);
//save record to pass table
mysql_query("INSERT INTO passtab(......) VALUES(....);",$conn);
//remove data from origin table
mysql_query("DELETE FROM testresultAUG2012 WHERE Studentname = '$name' AND testbatch = $testbatch AND Subject=$subject AND result = 'PASS' AND class = '$classname';",$conn);
$pass++;
}
//moveFailed
$selectfail = mysql_query("SELECT * FROM testresultAUG2012 WHERE actualmonth='AUG' AND testresult = 'PASS' AND classname = '$classselect' AND educationsubject = $subjectselect;",$conn);
$totalfail = mysql_num_rows($selectfail);
$fail=0;
while($fail<$totalfail)
{
$name=mysql_result($selectfail, $fail, "Studentname");
$subject=mysql_result($selectpass, $fail, "Subject");
$testbatch=mysql_result($selectfail, $fail, "testbatch");
$classname=mysql_result($selectfail, $fail, "class");
$lecturer=mysql_result($selectfail, $fail, "lecturer");
$date=mysql_result($selectfail, $fail, "date");
$month=mysql_result($selectfail, $fail, "month");
$time=mysql_result($selectfail, $fail, "time");
$state=mysql_result($selectfail, $fail, "result");
//count total fail subject and add 1
mysql_query("UPDATE Student SET totalfail = totalfail + 1 WHERE Studentname = '$name';",$conn);
//save record to fail table
mysql_query("INSERT INTO failtab(....) VALUES(...);",$conn);
//remove data from origin table
mysql_query("DELETE FROM testresultAUG2012 WHERE Studentname = '$name' AND testbatch = $testbatch AND Subject=$subject AND result = 'FAIL' AND class = '$classname';",$conn);
$fail++;
}
}
?>
<?php
$relatedclass=$_POST[classup];
$relatedsubject=$_POST[subject];
spread($relatedclass,$relatedsubject);
echo "<center>Spread Completed !!!</CENTER>";
?>
<? ob_flush(); ?>