我有一个脚本,我用来检查我的数据库中的应用程序的状态,每次用户提交一个应用程序时,数据库中有4列,' form1_completed',' form2_completed&# 39;,' form3_completed'和' form4_completed'这些中的每一个都将从“不”中更新。到了“是”'取决于他们提交的申请。
mysql查询基本上搜索数据库中设置为“没有”的任何行,即form1_completed =' no'或form2_completed =' no'如果这些中的任何一个被设置为“不”。它说申请流程的状态正在等待
同样,如果用户提交了所有应用程序,则所有4个列都将更新为“是”'我的查询的第二部分告诉我们申请流程已经完成。
现在我在我的代码中引入了另一个元素,如果用户提交了一个应用程序并且他们填写错误或者他们没有通过初始检查,那么数据库中的一个列称为' status& #39;将更新为'失败'。
所以我想做的是,如果状态是'列的值为'失败'在其中我希望应用程序进程被列为“失败的”#39;而不是等待,但因为4列中的一个或多个; ' form1_completed',' form2_completed'等等仍然没有在他们中然后mysql回应这个作为应用程序挂起仍然。但我想要做的是说一些如果状态如何'设置为失败然后说申请流程失败,否则如果状态'是空的或者是失败的'不存在然后申请流程将待决
请有人告诉我如何修改我的脚本以使其工作
<?php include 'config.php';
$data = mysql_query("SELECT *, TIMESTAMPDIFF(DAY, date, CURDATE()) AS expire_date
FROM supplier_session
WHERE form1_completed = 'No'
OR form2_completed = 'No'
OR form3_completed = 'No'
OR form4_completed = 'No'
ORDER BY expire_date ASC")
or die(mysql_error());
echo "<table class=\"table\" style=\"width:995px; font-family: 'Lucida Grande', Tahoma, Verdana, Arial, sans-serif;
font-size:11px;\" >
<tr>
<td style=\"width:100px;\">ID:</td><td>Company Name:</td><td>Company Reg No:</td><td>Application Started:</td><td style=\"width:200px;\">Application Duration:</td><td>Status:</td></tr>";
while($row = mysql_fetch_array( $data )) {
$days = $row['expire_date'];
$when = $days*0;
$str = $row['expire_date'];
$str2 = substr($str, 0); // "quick brown fox jumps over the lazy dog."
if ($when <= 31){
echo "<tr><td style=\"width:100px;\"><p>".$row['id'] . "</p></td>";
echo "<td style=\"width:150px;\"><p>".$row['company_name'] . "</p></td>";
echo "<td style=\"width:150px;\"><p>".$row['company_reg_number'] . "</p></td>";
echo "<td>"; echo date('d/m/Y',strtotime($row['date'])); echo "</td>";
if ($days >= 8) {
echo "<td style=\"width:200px;\"><p>";
print ($str2 -7);
echo " days overdue</td>";
}
elseif ($when <= 7){
echo "<td style=\"width:200px;\"><p>{$str2} of 7 days past</td>";
}
}
$q2 = "SELECT * FROM supplier_session
WHERE form1_completed = 'NO'
OR form2_completed = 'NO'
OR form3_completed = 'NO'
OR form4_completed = 'NO'"
or die (mysql_error());
$result2 = mysql_query($q2);
$count2 = mysql_num_rows($result2);
echo "<td>";
echo "Pending</td>";
echo "<tr>";
}
$data2 = mysql_query("SELECT *,
TIMESTAMPDIFF(DAY, date, CURDATE()) AS expire_date
FROM supplier_session
WHERE form1_completed = 'Yes'
AND form2_completed = 'Yes'
AND form3_completed = 'Yes'
AND form4_completed = 'Yes'
ORDER BY expire_date ASC")
or die(mysql_error());
while($row = mysql_fetch_array( $data2 )) {
$days = $row['expire_date'];
$when = $days*0;
$str = $row['expire_date'];
$str2 = substr($str, 0); // "quick brown fox jumps over the lazy dog."
if ($when <= 31){
echo "<tr><td style=\"width:100px;\"><p>".$row['id'] . "</p></td>";
echo "<td style=\"width:150px;\"><p>".$row['company_name'] . "</p></td>";
echo "<td style=\"width:150px;\"><p>".$row['company_reg_number'] . "</p></td>";
echo "<td style=\"width:203px;\">"; echo date('d/m/Y',strtotime($row['date'])); echo "</td>";
echo "<td style=\"width:200px;\"><p> Completed in ";
print ($str2);
echo " days</td>";
}
$q2 = "SELECT * FROM supplier_session
form1_completed = 'Yes' AND form2_completed = 'Yes' AND form3_completed = 'Yes' AND form4_completed = 'Yes'"
or die (mysql_error());
$result2 = mysql_query($q2);
$count2 = mysql_num_rows($result2);
echo "<td>";
echo "Completed</td>";
echo "<tr>";
}
echo "</table>"; //Close the table in HTML
?>
答案 0 :(得分:0)
更改各种查询以包括对任何表单*列失败的测试。
以下是“待处理”查询:
SELECT * FROM supplier_session
WHERE
( form1_completed = 'NO'
OR form2_completed = 'NO'
OR form3_completed = 'NO'
OR form4_completed = 'NO')
AND NOT ('failed' IN (form1_completed,
form2_completed,
form3_completed,
form4_completed ))