从多个表中获取数据 - 单个数据库



当 AND icutype = 添加到 where 子句中时,我没有收到任何错误,也没有 $con$con 2 和 3 的值$icutype。删除后,我正确获得总输出。

<?Php
$con = mysqli_connect("localhost","root","","nimicudb");
$con2 = mysqli_connect("localhost","root","","nimicudb");
$con3 = mysqli_connect("localhost","root","","nimicudb");
if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
die();
}
if(!empty($_POST) && $_SERVER['REQUEST_METHOD'] == 'POST'){
$icutype = $_POST["icutype"];
$fromdate = $_POST['fromdate'];
$todate = $_POST['todate'];
$sql1= mysqli_query($con,"SELECT COUNT(name) FROM `patients` WHERE date BETWEEN '$fromdate' AND '$todate' AND icutype = '$icutype'");
$row = mysqli_fetch_array($sql1);
$totalpatients=$row[0];
$sql2= mysqli_query($con,"SELECT icubedstrength FROM `icustrength` WHERE icuname = '$icutype' ");
$row1 = mysqli_fetch_array($sql2);
$totalbeds=$row1[0];
$sql3= mysqli_query($con2,"SELECT COUNT(icureturn48) FROM `patients1` WHERE date BETWEEN '$fromdate' AND '$todate' AND icutype = '$icutype' ");
$row2 = mysqli_fetch_array($sql3);
$totalicureturn48=$row2[0];
$sql4= mysqli_query($con,"SELECT COUNT(datedischarge) FROM `patients` WHERE date BETWEEN '$fromdate' AND '$todate' AND icutype = '$icutype'");
$row3 = mysqli_fetch_array($sql4);
$totaldischarge=$row3[0];
$sql5= mysqli_query($con3,"SELECT COUNT(reintbn48) FROM `patients2` WHERE date BETWEEN '$fromdate' AND '$todate' AND icutype = '$icutype'");
$row4 = mysqli_fetch_array($sql5);
$totalreintubation=$row4[0];
$sql6= mysqli_query($con,"SELECT COUNT(tubedate) FROM `patients` WHERE date BETWEEN '$fromdate' AND '$todate' AND icutype = '$icutype'");
$row5 = mysqli_fetch_array($sql6);
$totalintubation=$row5[0];
$totaldays = (strtotime($todate) - strtotime($fromdate)) / (60 * 60 * 24);
echo  "TOTAL DAYS - $totaldays </br>";
echo "TOTAL PATIENTS - $totalpatients</br>";
echo "TOTAL BEDS - $totalbeds</br>";
echo "TOTAL discharge - $totaldischarge</br>";
echo "TOTAL intubation - $totalintubation</br>";
echo "TOTAL PATIENTS returned - $totalicureturn48</br>";
echo "TOTAL reintubation - $totalreintubation</br>";
$icureturnrate=(round(($totalicureturn48/$totaldischarge)*100));
$reintubation_rate=(round(($totalreintubation/$totalintubation)*100));
$urate=(round(($totalpatients/$totalbeds)*$totaldays));
echo "utilization rate is  : $urate</br>";
echo "% Return to ICU within 48 hours is  : $icureturnrate </br>";
echo "% Re-intubation rate is  : $reintubation_rate";
}
?>

<html>

<form action='search.php' method='POST'>
<h5>SELECT ICU</h5>
<select name='icutype' >
<option value="EICU">EICU</option>
<option value="NMICU">NMICU</option>
<option value="NSICU">NSICU</option>
<option value="SBICU">SBICU</option>
</select>
</br>

FROM DATE<input type="date" name="fromdate" value="<?php echo date('Y-m-d', strtotime('-30 days')); ?>"></br>

TO DATE<input type="date" name="todate" value="<?php echo date('Y-m-d'); ?>"></br>

<input type='submit' name='calsubmit' value="CALCULATE"/>
</form>

</html>

这是我需要建议的页面。

显示的输出如下所示

TOTAL DAYS - 30
TOTAL PATIENTS - 1
TOTAL BEDS - 6
TOTAL discharge - 1
TOTAL intubation - 1
**TOTAL PATIENTS returned - 0
**TOTAL reintubation - 0
utilization rate is : 5
% Return to ICU within 48 hours is : 0
% Re-intubation rate is : 0 

当 和 添加到 WHERE 子句 (AND icutype = '$icutype'( 时,**标记的项目没有给出任何输出

海家伙,我解决了。 问题是一些空格与 icutype 列中的数据一起保存。我将 icutype =$icutype 更改为 icutype LIKE '%$icutype%',它就像地狱一样工作。 谢谢大家。

最新更新