我有几个条件,我正在寻找输出不同的样式。一切都有效,但这一部分,我不能为我的生活理解为什么它不会输出我想要的。
我可以在数据库中验证是否有包含这两个条件的记录。就我而言,我在看:
elseif (($t4 == '' || $t4 == NULL )&& $nordvmfollowup == '1'){
echo '<tr>
<td><div valign="top" align="center">' . '<a class="btn-sm btn-secondary" target="_blank" href="insert_patient_data.php?id=' . $row['pdoseID'] . '"> ' . "Edit". '</a>' . '</td>
<td><div align="left">'.$row['patientID'].'</div></td>
<td><div align="left">'.$row['lastname'].'</div></td>
<td><div align="left">'.$row['firstname'].'</div></td>
<td><div align="left">'.$row['breed'].'</div></td>
<td><div align="left">'.$row['gender'].'</div></td>
<td><div valign="top" align="left">'.date('d-M-Y', strtotime($row['date_injected'])).'</div></td>
<td><div align="left">'.$row['dose'].' mCi</div></td>
<td><div align="left">'.$row['preT4'].'</div></td>
<td ><div align="left">NF</div></td>
<td><div align="left">'.$datechecked.'</div></td>
</tr>';
}
就在我的时间之后:
$t4 = $row['postT4'];
$nordvmfollowup = $row['nordvmfollowup'];
我尝试过以下条件,没有任何内容会在单元格中输出字母NF。
elseif ($t4 == '' && $nordvmfollowup == '1')
elseif ($t4 == NULL && $nordvmfollowup == '1')
elseif (($t4 == '' || $t4 == NULL ) && $nordvmfollowup == '1')
elseif ((!isset($t4)) && $nordvmfollowup == '1')
所有其他条件陈述都有效,这让我觉得我不能
我的完整代码:
<?php
define('DB_SERVER', "xxxx");
define('DB_USER', "xxxx");
define('DB_PASSWORD', "xxxx");
define('DB_TABLE', "xxxx");
// The procedural way
$mysqli = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD, DB_TABLE);
$mysqli->set_charset("utf8");
$mysqli->query("SET NAMES 'utf8'");
if (mysqli_connect_errno($mysqli)) {
trigger_error('Database connection failed: ' . mysqli_connect_error(), E_USER_ERROR);
}
$query = "
SELECT i131.pdoseID, i131.patientID, i131.lastname, i131.firstname, i131.dose, i131.date_injected, i131.pre_tapazole_t4 AS preT4, i131.recheck_t4 AS postT4, i131.datechecked, b.breed, g.gender, i131.recheck_t4_range_low, i131.recheck_t4_range_high, i131.deceased, i131.nordvmfollowup, i131.recheck_t4
FROM tbl_I131_data i131
LEFT JOIN tbl_I131_breeds b
ON i131.breed = b.breedID
LEFT JOIN tbl_I131_gender g
ON i131.gender = g.genderID
WHERE i131.isotope = '1'
GROUP BY i131.pdoseID, i131.patientID, i131.lastname, i131.firstname, i131.dose, i131.date_injected, i131.pre_tapazole_t4, i131.recheck_t4, i131.datechecked, b.breed, g.gender, i131.recheck_t4_range_low, i131.recheck_t4_range_high, i131.deceased, i131.nordvmfollowup
ORDER BY i131.date_injected DESC";
$result = mysqli_query($mysqli, $query) or trigger_error("Query Failed! SQL: $query - Error: ". mysqli_error($mysqli), E_USER_ERROR);
echo "
<table width='1280px;' class='tablesorter-dropbox table-responsive ui-table-reflow'>";
echo "<thead class='thead-inverse'>";
echo "<tr>";
echo "<th class='filter-false' data-sorter='false'><div align='left'> </div></th>
<th ><div align='left'>Patient ID</div></th>
<th ><div align='left'>Last Name</div></th>
<th ><div align='left'>First Name</div></th>
<th class='filter-select filter-onlyAvail'><div align='left'>Breed</div></th>
<th class='filter-select filter-onlyAvail'><div align='left'>Gender</div></th>
<th class='filter-false' ><div align='left'>Date Injected</div></th>
<th class='filter-false' data-sorter='false'><div align='left'>Dose</div></th>
<th class='filter-false'><div align='left'>Pre Tx T4</div></th>
<th class='filter-false' ><div align='left'>Post Tx T4</div></th>
<th class='filter-false'><div align='left'>Recheck Date</div></th>";
echo "</tr>";
echo "</thead>";
echo "<tfoot>";
echo "<tr>";
echo "<th class='filter-false' data-sorter='false'><div align='left'> </div></th>
<th ><div align='left'>Patient ID</div></th>
<th ><div align='left'>Last Name</div></th>
<th ><div align='left'>First Name</div></th>
<th class='filter-select filter-onlyAvail'><div align='left'>Breed</div></th>
<th class='filter-select filter-onlyAvail'><div align='left'>Gender</div></th>
<th class='filter-false' ><div align='left'>Date Injected</div></th>
<th class='filter-false' data-sorter='false'><div align='left'>Dose</div></th>
<th class='filter-false'><div align='left'>Pre Tx T4</div></th>
<th class='filter-false' ><div align='left'>Post Tx T4</div></th>
<th class='filter-false'><div align='left'>Recheck Date</div></th>";
echo "</tr>";
echo "<tr>";
echo "<th colspan='11' class='ts-pager'>";
echo "<div class='form-inline'>";
echo " <div class='btn-group btn-group-sm mx-1' role='group'>";
echo " <button type='button' class='btn btn-secondary first' title='first'>⇤</button>";
echo " <button type='button' class='btn btn-secondary prev' title='previous'>←</button>";
echo " </div>";
echo " <span class='pagedisplay'></span>";
echo " <div class=btn-group btn-group-sm mx-1' role='group'>";
echo " <button type='button' class='btn btn-secondary next' title='next'>→</button>";
echo " <button type='button' class='btn btn-secondary last' title='last'>⇥</button>";
echo " </div>";
echo " <select class='form-control-sm custom-select px-1 pagesize' title='Select page size'>";
echo " <option selected='selected' value='15'>15</option>";
echo " <option value='30'>30</option>";
echo " <option value='50'>50</option>";
echo " <option value='100'>100</option>";
echo " <option value='all'>All Rows</option>";
echo " </select>";
echo " <select class='form-control-sm custom-select px-4 mx-1 pagenum' title='Select page number'></select>";
echo " </div>";
echo " </th>";
echo "</tr>";
echo "</tfoot>";
echo "<tbody>";
if($result) {
while($row = mysqli_fetch_assoc($result)) {
if ($row['datechecked']==''){
$datechecked = NULL;
}
else {
$datechecked = date('d-M-Y', strtotime($row['datechecked']));
}
$t4 = $row['postT4'];
$t4_low = $row['recheck_t4_range_low'];
$t4_high = $row['recheck_t4_range_high'];
$deceased = $row['deceased'];
$nordvmfollowup = $row['nordvmfollowup'];
if ($t4 == '' && $deceased == ''){
echo '<tr>
<td><div valign="top" align="center">' . '<a class="btn-sm btn-secondary" target="_blank" href="insert_patient_data.php?id=' . $row['pdoseID'] . '"> ' . "Edit". '</a>' . '</td>
<td><div align="left">'.$row['patientID'].'</div></td>
<td><div align="left">'.$row['lastname'].'</div></td>
<td><div align="left">'.$row['firstname'].'</div></td>
<td><div align="left">'.$row['breed'].'</div></td>
<td><div align="left">'.$row['gender'].'</div></td>
<td><div valign="top" align="left">'.date('d-M-Y', strtotime($row['date_injected'])).'</div></td>
<td><div align="left">'.$row['dose'].' mCi</div></td>
<td><div align="left">'.$row['preT4'].'</div></td>
<td><div align="left"> </div></td>
<td><div align="left">'.$datechecked.'</div></td>
</tr>';
}
elseif ($t4 == '' && $deceased == '1'){
echo '<tr>
<td><div valign="top" align="center">' . '<a class="btn-sm btn-secondary" target="_blank" href="insert_patient_data.php?id=' . $row['pdoseID'] . '"> ' . "Edit". '</a>' . '</td>
<td><div align="left">'.$row['patientID'].'</div></td>
<td><div align="left">'.$row['lastname'].'</div></td>
<td><div align="left">'.$row['firstname'].'</div></td>
<td><div align="left">'.$row['breed'].'</div></td>
<td><div align="left">'.$row['gender'].'</div></td>
<td><div valign="top" align="left">'.date('d-M-Y', strtotime($row['date_injected'])).'</div></td>
<td><div align="left">'.$row['dose'].' mCi</div></td>
<td><div align="left">'.$row['preT4'].'</div></td>
<td bgcolor="#000000"><div align="left"> </div></td>
<td><div align="left">'.$datechecked.'</div></td>
</tr>';
}
elseif (($t4 == '' || $t4 == NULL )&& $nordvmfollowup == '1'){
echo '<tr>
<td><div valign="top" align="center">' . '<a class="btn-sm btn-secondary" target="_blank" href="insert_patient_data.php?id=' . $row['pdoseID'] . '"> ' . "Edit". '</a>' . '</td>
<td><div align="left">'.$row['patientID'].'</div></td>
<td><div align="left">'.$row['lastname'].'</div></td>
<td><div align="left">'.$row['firstname'].'</div></td>
<td><div align="left">'.$row['breed'].'</div></td>
<td><div align="left">'.$row['gender'].'</div></td>
<td><div valign="top" align="left">'.date('d-M-Y', strtotime($row['date_injected'])).'</div></td>
<td><div align="left">'.$row['dose'].' mCi</div></td>
<td><div align="left">'.$row['preT4'].'</div></td>
<td ><div align="left">NF</div></td>
<td><div align="left">'.$datechecked.'</div></td>
</tr>';
}
elseif ($t4 <= $t4_low) {
echo '<tr>
<td><div valign="top" align="center">' . '<a class="btn-sm btn-secondary" target="_blank" href="insert_patient_data.php?id=' . $row['pdoseID'] . '"> ' . "Edit". '</a>' . '</td>
<td><div align="left">'.$row['patientID'].'</div></td>
<td><div align="left">'.$row['lastname'].'</div></td>
<td><div align="left">'.$row['firstname'].'</div></td>
<td><div align="left">'.$row['breed'].'</div></td>
<td><div align="left">'.$row['gender'].'</div></td>
<td><div valign="top" align="left">'.date('d-M-Y', strtotime($row['date_injected'])).'</div></td>
<td><div align="left">'.$row['dose'].' mCi</div></td>
<td><div align="left">'.$row['preT4'].'</div></td>
<td bgcolor="#e4ffc9"><div align="left">'.$row['postT4'].'</div></td>
<td><div align="left">'.$datechecked.'</div></td>
</tr>';
}
elseif ($t4 >= $t4_low && $t4 < $t4_high){
echo '<tr>
<td><div valign="top" align="center">' . '<a class="btn-sm btn-secondary" target="_blank" href="insert_patient_data.php?id=' . $row['pdoseID'] . '"> ' . "Edit". '</a>' . '</td>
<td><div align="left">'.$row['patientID'].'</div></td>
<td><div align="left">'.$row['lastname'].'</div></td>
<td><div align="left">'.$row['firstname'].'</div></td>
<td><div align="left">'.$row['breed'].'</div></td>
<td><div align="left">'.$row['gender'].'</div></td>
<td><div valign="top" align="left">'.date('d-M-Y', strtotime($row['date_injected'])).'</div></td>
<td><div align="left">'.$row['dose'].' mCi</div></td>
<td><div align="left">'.$row['preT4'].'</div></td>
<td><div align="left">'.$row['postT4'].'</div></td>
<td><div align="left">'.$datechecked.'</div></td>
</tr>';
}
elseif ($t4 >= $t4_high){
echo '<tr>
<td><div valign="top" align="center">' . '<a class="btn-sm btn-secondary" target="_blank" href="insert_patient_data.php?id=' . $row['pdoseID'] . '"> ' . "Edit". '</a>' . '</td>
<td><div align="left">'.$row['patientID'].'</div></td>
<td><div align="left">'.$row['lastname'].'</div></td>
<td><div align="left">'.$row['firstname'].'</div></td>
<td><div align="left">'.$row['breed'].'</div></td>
<td><div align="left">'.$row['gender'].'</div></td>
<td><div valign="top" align="left">'.date('d-M-Y', strtotime($row['date_injected'])).'</div></td>
<td><div align="left">'.$row['dose'].' mCi</div></td>
<td><div align="left">'.$row['preT4'].'</div></td>
<td bgcolor="#ff8494"><div align="left">'.$row['postT4'].'</div></td>
<td><div align="left">'.$datechecked.'</div></td>
</tr>';
}
}
echo "</tbody>";
echo "</table>";
}
else {
echo 'All wipe tests have been completed';
}
mysqli_close($mysqli);
?>
答案 0 :(得分:0)
你在这一行上缺少关闭'div':
<td><div valign="top" align="center">' . '<a class="btn-sm btn-secondary" target="_blank" href="insert_patient_data.php?id=' . $row['pdoseID'] . '"> ' . "Edit". '</a>' . '</td>
尝试使用此代码,从if($result) {
替换为EOF:
if($result)
{
while( $row = mysqli_fetch_assoc($result) )
{
if ( $row['datechecked'] == '')
{
$datechecked = NULL;
}
else
{
$datechecked = date('d-M-Y', strtotime($row['datechecked']));
}
$t4 = $row['postT4'];
$t4_low = $row['recheck_t4_range_low'];
$t4_high = $row['recheck_t4_range_high'];
$deceased = $row['deceased'];
$nordvmfollowup = $row['nordvmfollowup'];
echo '<tr>
<td><div valign="top" align="center">' . '<a class="btn-sm btn-secondary" target="_blank" href="insert_patient_data.php?id=' . $row['pdoseID'] . '"> ' . "Edit". '</a>' . '</div></td>
<td><div align="left">'.$row['patientID'].'</div></td>
<td><div align="left">'.$row['lastname'].'</div></td>
<td><div align="left">'.$row['firstname'].'</div></td>
<td><div align="left">'.$row['breed'].'</div></td>
<td><div align="left">'.$row['gender'].'</div></td>
<td><div valign="top" align="left">'.date('d-M-Y', strtotime($row['date_injected'])).'</div></td>
<td><div align="left">'.$row['dose'].' mCi</div></td>
<td><div align="left">'.$row['preT4'].'</div></td>';
if ($t4 == '' && $deceased == '')
{
echo '<td><div align="left"> </div></td>';
}elseif ($t4 == '' && $deceased == '1')
{
echo '<td bgcolor="#000000"><div align="left"> </div></td>';
}elseif (($t4 == '' || $t4 == NULL ) && $nordvmfollowup == '1')
{
echo '<td ><div align="left">NF</div></td>';
}elseif ($t4 <= $t4_low)
{
echo '<td bgcolor="#e4ffc9"><div align="left">'.$row['postT4'].'</div></td>';
}elseif ($t4 >= $t4_low && $t4 < $t4_high)
{
echo '<td><div align="left">'.$row['postT4'].'</div></td>;
<td><div align="left">'.$datechecked.'</div></td>
</tr>';
}elseif ($t4 >= $t4_high){
echo '<td bgcolor="#ff8494"><div align="left">'.$row['postT4'].'</div></td>';
}
echo '<td><div align="left">'.$datechecked.'</div></td>
</tr>';
}
}else
{
echo '<tr><td colspan="11">All wipe tests have been completed</td></tr>';
}
echo "</tbody>";
echo "</table>";
mysqli_close($mysqli);
我没有检查逻辑条件,因为我不知道数据和目标。
答案 1 :(得分:0)
你有一个逻辑问题:你的情况可能正常,但它永远不会被评估,因为前两个中的任何一个都已经被满足。
您的代码如下:
if ($t4 == '' && $deceased == ''){
// some code
}
elseif ($t4 == '' && $deceased == '1'){
// some code
}
elseif (($t4 == '' || $t4 == NULL )&& $nordvmfollowup == '1'){
// some code
}
...
您已在评论中确认$deceased
可以为空或1。
因此,当代码的前3个条件转换为:
时,第三个条件永远不会达到/匹配if ($t4 == ''){
// If this condition is not met...
if ($deceased == ''){
// some code
}
// Then this condition is met.
elseif ($deceased == '1'){
// some code
}
// So this condition is never evaluated.
elseif ($nordvmfollowup == '1'){
// some code
}
}
...
因此,当$t4 == ''
(为空)时,两个内部条件中的任何一个都是true
,因此永远不会达到第三个条件。