(php)MySQL查询需要很长时间才能执行

时间:2014-01-20 11:22:27

标签: php sql performance mysqli timeout

我有以下PHP SQL语句在2 for循环中执行,第一个从1到20计数(给出每个问题),第二个从1计数到所选择的多个主题。

$queryA = mysqli_query($con, "SELECT * FROM subjectReview WHERE a = 1 AND question = '$y' AND course_code = '$coursePode[$l]'");
$totalsA = mysqli_num_rows($queryA);
$percentageA = 0;
$percentageSa = 0;
$querySa = mysqli_query($con, "SELECT * FROM subjectReview WHERE sa = 1 AND question = '$y' AND course_code = '$coursePode[$l]'");
$totalsSa = mysqli_num_rows($querySa);
$queryNAOD = mysqli_query($con, "SELECT * FROM subjectReview WHERE naod = 1 AND question = '$y' AND course_code = '$coursePode[$l]'");
$totalsNAOD = mysqli_num_rows($queryNAOD);
$percentageNAOD = 0;
$queryD = mysqli_query($con, "SELECT * FROM subjectReview WHERE d = 1 AND question = '$y' AND course_code = '$coursePode[$l]'");
$totalsD = mysqli_num_rows($queryD);
$querySd = mysqli_query($con, "SELECT * FROM subjectReview WHERE sd = 1 AND question = '$y' AND course_code = '$coursePode[$l]'");
$totalsSd = mysqli_num_rows($querySd);
$percentageSd = 0;
$percentageD = 0;
$totals = 0;
  • 之后,结果将通过此代码打印到tablie -


echo '<tr>
<td>' . $coursePitle[$l] . '</td>
<td>' . $totalsSa . '</td>
<td>' . $percentageSa . '</td> 
<td>' . $totalsA . '</td>
<td>' . $percentageA . '</td>
<td>' . $totalsNAOD . '</td>
<td>' . $percentageNAOD . '</td>
<td>' . $totalsD . '</td>
<td>' . $percentageD . '</td>
<td>' . $totalsSd . '</td>
<td>' . $percentageSd . '</td>
<td>' . $totals . '</td>
</tr>';

表哈林是在两个循环之间定义的,对于每个问题,我们打印统计信息,每个主题都进入一行。

如果我删除变量,页面加载速度相对较快(10-15秒),如果我将代码保留在那里,但是,页面加载时间过长会失败。

有什么想法? 在此先感谢:)

0 个答案:

没有答案