จับ Content มันรวมกันยังไงค่ะ ให้อยู่หัวข้อเดียว ตอนนี้มันออกมาแบบ รุปที่ 1 คะ
Code (PHP)
while($Result = odbc_fetch_array ($objroom))
{
$room=$Result["room"];
?>
<tr>
<th scope="row" colspan="10">Room <?= $room ?></th>
</tr>
<tr>
<td><?= $no ?></td>
<td>Mark</td>
<td>Otto</td>
<td>@mdo</td>
<td>Mark</td>
<td>Otto</td>
<td>@mdo</td>
<td>Mark</td>
<td>Otto</td>
<td>@mdo</td>
</tr>
<?php
$no++;
}
?>
<tr>
<th scope="row" colspan="10" class="text-center">Total.....ราย</th>
</tr>
Date :
2018-05-05 13:09:42
By :
mr.v
ขอโค้ดเต็มๆหน่อยครับ แล้ว Total นี่เอาไปแสดงที่ รวม......ราย นี้หรอครับ มันคือจำนวนแถวหรอครับ
Date :
2018-05-05 14:19:27
By :
nPointXer
ไม่เอาส่วน sql ให้ดูนะคะ มันยาวมาก
Code (PHP)
<?php
$objAdmit = odbc_exec($conn,$strAdmit) or die ("Error SQL [".$strAdmit."]");
while($ResultAdmit = odbc_fetch_array ($objAdmit))
{
$Ward=$ResultAdmit["Ward"];
$AdmDateTime=$ResultAdmit["AdmDateTime"];
$AN=$ResultAdmit["AN"];
$HN=$ResultAdmit["HN"];
$HNBedNo=$ResultAdmit["HNBedNo"];
$SuffixName=$ResultAdmit["SuffixName"];
$FirstName=$ResultAdmit["FirstName"];
$LastName=$ResultAdmit["LastName"];
$RemarksMemo=$ResultAdmit["RemarksMemo"];
$NameDoctor=$ResultAdmit["LocalName"];
?>
<tr>
<th scope="row" colspan="10">WARD <?= $Ward ?></th>
</tr>
<tr>
<td><?= $no ?></td>
<td><?= substr($AdmDateTime,0,-11)?></td>
<td><?=$AN?></td>
<td><?=$HN?></td>
<td><?=$HNBedNo?></td>
<td class="text-wrap">
<?=iconv('TIS-620','UTF-8',substr($SuffixName,1))?>
<?=iconv('TIS-620','UTF-8',substr($FirstName,1))?>
<?=iconv('TIS-620','UTF-8',substr($LastName,1))?></td>
<td class="text-wrap"><?=iconv('TIS-620','UTF-8',$RemarksMemo)?></td>
<td>Mark</td>
<td><?=iconv('TIS-620','UTF-8',substr($NameDoctor,1))?></td>
<td>@DcgType</td>
</tr>
<tr>
<th scope="row" colspan="10" class="text-center">Total.....ราย</th>
</tr>
<?php
$no++;
}
?>
Date :
2018-05-05 14:35:27
By :
nottpoo
ของผมที่ทำ
ผมใช้ while ซ้อน while ครับ อธิบายไม่เก่งอะ ลองอ่านๆดูละ
while แรก GROUP Ward มาว่ามีอะไรบ้าง, กี่รายการ
Code (SQL)
SELECT Ward, COUNT(Ward) AS NUMC
FROM TABLE
GROUP BY Ward
ORDER BY Ward ASC
while ที่สองก็คืออันที่เราทำนั่นแหละ ละก็เพิ่มเงื่อนไข
Code (SQL)
if($row['Ward'] == $ResultAdmit["Ward"]){
}
ลองเอา CODE ไปใช้ดูครับ ติดตรงไหนถามได้ครับ
Code (PHP)
<?php
$obj = odbc_exec($con....//ของ GROUP BY Ward
while($row = odbc_fetch_array ($obj)){
$no = 0;
$objAdmit = odbc_exec($conn,$strAdmit) or die ("Error SQL [".$strAdmit."]");
while($ResultAdmit = odbc_fetch_array ($objAdmit))
{
if($row['Ward'] == $ResultAdmit["Ward"]){
$no++;
$Ward=$ResultAdmit["Ward"];
$AdmDateTime=$ResultAdmit["AdmDateTime"];
$AN=$ResultAdmit["AN"];
$HN=$ResultAdmit["HN"];
$HNBedNo=$ResultAdmit["HNBedNo"];
$SuffixName=$ResultAdmit["SuffixName"];
$FirstName=$ResultAdmit["FirstName"];
$LastName=$ResultAdmit["LastName"];
$RemarksMemo=$ResultAdmit["RemarksMemo"];
$NameDoctor=$ResultAdmit["LocalName"];
echo '<tr>';
echo '<th scope="row" colspan="10">WARD '.$ResultAdmit["Ward"].'</th>';
echo '</tr>';
<tr>
<td><?= $no ?></td>
<td><?= substr($AdmDateTime,0,-11)?></td>
<td><?=$AN?></td>
<td><?=$HN?></td>
<td><?=$HNBedNo?></td>
<td class="text-wrap">
<?=iconv('TIS-620','UTF-8',substr($SuffixName,1))?>
<?=iconv('TIS-620','UTF-8',substr($FirstName,1))?>
<?=iconv('TIS-620','UTF-8',substr($LastName,1))?></td>
<td class="text-wrap"><?=iconv('TIS-620','UTF-8',$RemarksMemo)?></td>
<td>Mark</td>
<td><?=iconv('TIS-620','UTF-8',substr($NameDoctor,1))?></td>
<td>@DcgType</td>
</tr>
<?php
}//end if($row['Ward']
}//end while($ResultAdmit
echo '<tr>';
echo '<th scope="row" colspan="10" class="text-center"><B>Total '.$row['NUMC'].' ราย</B></th>';
echo '</tr>';
}//end while($row
?>
ลองแปลงเป็น php ทั้งหมด จะได้ดูง่ายๆ
Code (PHP)
<?php
$obj = odbc_exec($con....//ของ GROUP BY Ward
while($row = odbc_fetch_array ($obj)){
$no = 0;
$objAdmit = odbc_exec($conn,$strAdmit) or die ("Error SQL [".$strAdmit."]");
while($ResultAdmit = odbc_fetch_array ($objAdmit))
{
if($row['Ward'] == $ResultAdmit["Ward"]){
$no++;
echo '<tr>';
echo '<th scope="row" colspan="10">WARD '.$ResultAdmit["Ward"].'</th>';
echo '</tr>';
echo '<tr>';
echo '<td>'.$no.'</td>';
echo '<td>'.substr($ResultAdmit["AdmDateTime"],0,-11).'</td>';
echo '<td>'.$ResultAdmit["AN"].'</td>';
echo '<td>'.$ResultAdmit["HN"].'</td>';
echo '<td>'.$ResultAdmit["HNBedNo"].'</td>';
echo '<td class="text-wrap">';
echo iconv("tis-620", "utf-8",substr($ResultAdmit["SuffixName"],1) ).' ';
echo iconv("tis-620", "utf-8",substr($ResultAdmit["FirstName"],1) ).' ';
echo iconv("tis-620", "utf-8",substr($ResultAdmit["LastName"],1) ).' ';
echo '</td>';
echo '<td class="text-wrap">'.iconv("tis-620", "utf-8",$ResultAdmit["RemarksMemo"]).'</td>';
echo '<td>Mark</td>';
echo '<td>'.iconv("tis-620", "utf-8",substr($ResultAdmit["LocalName"],1) ).'</td>';
echo '<td>@DcgType</td>';
echo '</tr>';
}//end if($row['Ward']
}//end while($ResultAdmit
echo '<tr>';
echo '<th scope="row" colspan="10" class="text-center"><B>Total '.$row['NUMC'].' ราย</B></th>';
echo '</tr>';
}//end while($row
?>
ประวัติการแก้ไข 2018-05-05 15:35:24 2018-05-05 16:01:24
Date :
2018-05-05 15:28:24
By :
nPointXer
Code (PHP)
Total '.$row['NUMC'].' ราย
NUMC1 มาจากไหนคะ
Date :
2018-05-05 16:27:23
By :
nottpoo
Code (PHP)
Warning: odbc_exec(): SQL error: [Microsoft][SQL Server Native Client 11.0][SQL Server]Executing SQL directly; no cursor., SQL state 01000 in SQLExecDirect in D:\Apache24\htdocs\Bootstrap\Statistics\admit_today_count_ward.php on line 118
Error SQL [SELECT [10.1.1.230].DNHOSPITAL_TEST.dbo.HNIPD_BED.Ward, COUNT(Ward) AS NUMC FROM [10.1.1.230].DNHOSPITAL_TEST.dbo.HNIPD_BED.Ward GROUP BY Ward ORDER BY Ward ASC]
Code (PHP)
$strWard="SELECT [10.1.3.130].DNHOSPITAL_TEST.dbo.HNIPD_BED.Ward, COUNT(Ward) AS NUMC
FROM [10.1.3.130].DNHOSPITAL_TEST.dbo.HNIPD_BED.Ward
GROUP BY Ward
ORDER BY Ward ASC";
Code (PHP)
$objWard = odbc_exec($conn,$strWard) or die ("Error SQL [".$strWard."]"); //Error บรรทัดนี้ บอกว่าไม่ได้ปิด cursor
หาดีแล้วก็ปิดครบหมดนะ
Date :
2018-05-05 16:49:55
By :
nottpoo
หาย Error แล้วคะ
แต่ว่ารูปแบบยังไม่ออกแบบที่ต้องการ
Date :
2018-05-05 17:14:47
By :
nottpoo
ที่ปิด เพราะข้อมูลเปิดเผยไม่ได้คะ
Code (PHP)
<?php
$strWard = "SELECT a.Ward
FROM [0.0.0.000].DNHOSPITAL_TEST.dbo.HNIPD_BED a
GROUP BY a.Ward
ORDER BY a.Ward ASC";
$strAdmit = "
SELECT * FROM
(SELECT DNHOSPITAL_TEST.dbo.HNIPD_MASTER.AN,
DNHOSPITAL_TEST.dbo.HNIPD_MASTER.HN,
cast(DNHOSPITAL_TEST.dbo.HNIPD_MASTER.AdmDateTime as time) as AdmDateTime,
DNHOSPITAL_TEST.dbo.HNIPD_MASTER.DischargeCode,
DNHOSPITAL_TEST.dbo.HNIPD_DOCTOR.Doctor as DC,
DNHOSPITAL_TEST.dbo.HNDOCTOR_MASTER.Doctor,
DNHOSPITAL_TEST.dbo.HNDOCTOR_MASTER.LocalName,
DNHOSPITAL_TEST.dbo.HNIPD_BED.HNBedNo,
DNHOSPITAL_TEST.dbo.HNIPD_BED.Ward,
DNHOSPITAL_TEST.dbo.HNIPD_MEMO.RemarksMemo,
DNHOSPITAL_TEST.dbo.HNIPD_RIGHT.RightCode,
DNHOSPITAL_TEST.dbo.HNPAT_NAME.InitialNameCode,
DNHOSPITAL_TEST.dbo.DNSYSCONFIG.LocalName as SuffixName,
DNHOSPITAL_TEST.dbo.HNPAT_NAME.FirstName,
DNHOSPITAL_TEST.dbo.HNPAT_NAME.LastName
FROM DNHOSPITAL_TEST.dbo.HNIPD_MASTER
INNER JOIN DNHOSPITAL_TEST.dbo.HNIPD_DOCTOR
ON DNHOSPITAL_TEST.dbo.HNIPD_MASTER.AN = DNHOSPITAL_TEST.dbo.HNIPD_DOCTOR.AN
INNER JOIN DNHOSPITAL_TEST.dbo.HNDOCTOR_MASTER
ON DNHOSPITAL_TEST.dbo.HNIPD_MASTER.AdmDoctor = DNHOSPITAL_TEST.dbo.HNDOCTOR_MASTER.Doctor
INNER JOIN DNHOSPITAL_TEST.dbo.HNIPD_BED
ON DNHOSPITAL_TEST.dbo.HNIPD_MASTER.AN = DNHOSPITAL_TEST.dbo.HNIPD_BED.AN
INNER JOIN DNHOSPITAL_TEST.dbo.HNIPD_MEMO
ON DNHOSPITAL_TEST.dbo.HNIPD_MASTER.AN = DNHOSPITAL_TEST.dbo.HNIPD_MEMO.AN
INNER JOIN DNHOSPITAL_TEST.dbo.HNIPD_RIGHT
ON DNHOSPITAL_TEST.dbo.HNIPD_MASTER.AN = DNHOSPITAL_TEST.dbo.HNIPD_RIGHT.AN
INNER JOIN DNHOSPITAL_TEST.dbo.HNPAT_NAME
ON DNHOSPITAL_TEST.dbo.HNIPD_MASTER.HN = DNHOSPITAL_TEST.dbo.HNPAT_NAME.HN
INNER JOIN DNHOSPITAL_TEST.dbo.DNSYSCONFIG
ON DNHOSPITAL_TEST.dbo.HNPAT_NAME.InitialNameCode = DNHOSPITAL_TEST.dbo.DNSYSCONFIG.code
WHERE year(DNHOSPITAL_TEST.dbo.HNIPD_MASTER.AdmDateTime)='".$year."'
AND month(DNHOSPITAL_TEST.dbo.HNIPD_MASTER.AdmDateTime)='".$month."'
AND day(DNHOSPITAL_TEST.dbo.HNIPD_MASTER.AdmDateTime)='".$date."'
AND DNHOSPITAL_TEST.dbo.DNSYSCONFIG.CtrlCode ='10241') AS AdmitToday
ORDER BY AdmitToday.AdmDateTime ASC ";
$objWard = odbc_exec($conn,$strWard) or die ("Error SQL [".$strWard."]");
while($row = odbc_fetch_array($objWard))
{
$objAdmit = odbc_exec($conn,$strAdmit) or die ("Error SQL [".$strAdmit."]");
while($ResultAdmit = odbc_fetch_array ($objAdmit))
{
if($row['Ward'] == $ResultAdmit["Ward"])
{
$Ward=$ResultAdmit["Ward"];
$AdmDateTime=$ResultAdmit["AdmDateTime"];
$AN=$ResultAdmit["AN"];
$HN=$ResultAdmit["HN"];
$HNBedNo=$ResultAdmit["HNBedNo"];
$SuffixName=$ResultAdmit["SuffixName"];
$FirstName=$ResultAdmit["FirstName"];
$LastName=$ResultAdmit["LastName"];
$RemarksMemo=$ResultAdmit["RemarksMemo"];
$NameDoctor=$ResultAdmit["LocalName"];
?>
<tr>
<th scope="row" colspan="10">WARD <?= $Ward ?></th>
</tr>
<tr>
<td><?= $no ?></td>
<td><?= substr($AdmDateTime,0,-11)?></td>
<td><?=$AN?></td>
<td><?=$HN?></td>
<td><?=$HNBedNo?></td>
<td class="text-nowrap">
<?=iconv('TIS-620','UTF-8',substr($SuffixName,1))?>
<?=iconv('TIS-620','UTF-8',substr($FirstName,1))?>
<?=iconv('TIS-620','UTF-8',substr($LastName,1))?></td>
<td class="text-wrap"><?=iconv('TIS-620','UTF-8',$RemarksMemo)?></td>
<td>Mark</td>
<td><?=iconv('TIS-620','UTF-8',substr($NameDoctor,1))?></td>
<td>@DcgType</td>
</tr>
<?php
}//end if($row['Ward']
$no++;
}//end while($ResultAdmit
echo '<tr>';
echo '<th scope="row" colspan="10" class="text-center"><B>Total...ราย*</B></th>';
echo '</tr>';
}//end while($row
?>
Date :
2018-05-05 17:25:31
By :
nottpoo
เปลี่ยน
Code (SQL)
ORDER BY AdmitToday.AdmDateTime ASC
เป็น
Code (SQL)
ORDER BY AdmitToday.Ward ASC, AdmitToday.AdmDateTime ASC
แล้วลองทดสอบดูอีกครั้งหน่อยครับ ขอรูปด้วยนะครับ
Date :
2018-05-05 17:39:27
By :
nPointXer
เหมือนเดิมคะ
Date :
2018-05-05 17:52:31
By :
nottpoo
ได้แล้วนะคะ โดยความช่วยเหลือจาก Kaspersky
ประวัติการแก้ไข 2018-05-08 23:00:07
Date :
2018-05-05 19:37:54
By :
nottpoo
Load balance : Server 03