|
 |
|
ช่วยเรื่อง การUpdate เปลี่ยนสถานะหน่อยนะครับ ท่านผู้ใจดี |
|
 |
|
|
 |
 |
|
หลังจากเมื่อวานได้ถามให้พวกท่าน ๆชุลมุนวุ่นวายไป วันนี้ผมก็มีเรื่องมารบกวนอีกละ5 5
มาเริ่มกัน

ภาพที่ 1
จะเห็นว่าตารางข้างบน คือตารางแสดงการร้องขอ เข้ามานะครับ
แล้วจะมีท้าย ๆ record ก็จะมีฟิลด์ สถานะ นะครับ ผมคิดว่าจะใส่ค่าเป็น "1" แล้ว กำหนดค่า 1 ไปจอยฐานข้อมูล
ให้เช็คว่าถ้าเป็น ให้เป็น "รอดำเนินการ" หลังจากนั้นเมื่อผมกำ ฟิลด์สุดท้ายคือ "รับ" พอกดปั๊บนะครับ
"ไคล์แม็ก ๆ " ผมอยากให้ สถานะ Update เป็น "กำลังดำเนินการ" โดย!! ย้อนไปเมื่อเรากด "รับ" จะเด้งขึ้นลิงค์มาใหม่

ภาพที่ 2
คือลิงค์นี้นะครับ อ่า ต่อไป เมื่อผมกด "ตกลง" นั่นแหละครับ สถานะจาก "กำลังดำเนินการ" จะเปลี่ยนไปทันที เป็น "เสร็จสิ้นการดำเนินการ"

ภาพที่ 3
เหมือนกันครับ ลิงค์ข้างบนต่อไปนี้ คือ จะเหมือนกับ ภาพที่ 1 สถานะของตารางจะเปลี่ยนพร้อม ๆกัน
เมื่อกด "รับ" ก็เปลี่ยนสถานะ เมื่อ กด "ตกลง" จาก ภาพที่ 2
พอจะเข้าใจไหมครับ
Code ภาพที่ 1
<tbody>
<?php
include('include/function.php');
$dblink = connect_db();
$strSQL = "SELECT autoid,typePT,hn,vn,pname,fname,lname,wardAC,WantOC,WantWC,WantWB,WantBB,TollN,TollOG,TollSL,ordercradler FROM addpatient";
$resultSQL = mysqli_query($dblink,$strSQL);
while ($rows = mysqli_fetch_array($resultSQL)){
?>
<tr bgcolor="#FFFFFF">
<td valign="middle"><?=$rows['autoid']?></td>
<td valign="middle"><?=get_PTName($rows['typePT'])?></td>
<td valign="middle"><?=$rows['hn']?></td>
<td valign="middle"><?=$rows['vn']?></td>
<td valign="middle"><?=$rows['pname']?></td>
<td valign="middle"><?=$rows['fname']?></td>
<td valign="middle"><?=$rows['lname']?></td>
<td valign="middle"><?=get_Wdname($rows['wardAC'])?></td>
<td valign="middle"><?=get_WtOC($rows['WantOC'])?>
<?=get_WtWC($rows['WantWC'])?>
<?=get_WtB($rows['WantWB'])?>
<?=get_WtBB($rows['WantBB'])?></td>
<td valign="middle"><?=get_TlN($rows['TollN'])?>
<?=get_TlOG($rows['TollOG'])?>
<?=get_TlSL($rows['TollSL'])?></td>
<td valign="middle"></td>
<td width="100" align="center"><a href="showRequest.php?autoid=<?=$rows['autoid']?>" target="_blank">รับ</a></td>
</tr>
<?
} // end loop
?>
</tbody>
</table>
Code ภาพที่ 2
<?php
include('include/function.php');
$dblink = connect_db();
$strSQL = "SELECT autoid,typePT,hn,vn,pname,fname,lname,wardAC,WantOC,WantWC,WantWB,WantBB,TollN,TollOG,TollSL FROM addpatient WHERE autoid='$autoid'";
$resultSQL = mysqli_query($dblink,$strSQL);
while ($rows = mysqli_fetch_array($resultSQL)){
?>
</span></p>
<Table width="590" border="3" align="center" bordercolor="#FF9F00">
<tr>
<td colspan=3 align="Center" bgcolor="#FFFFFF" > ลำดับที่ :: <y><?=$rows['autoid']?></y> ประเภทผู้ป่วย ::
<y><?=get_PTName($rows['typePT'])?> </y>
</tr>
<tr>
<td colspan="2" align="left" bgcolor="#FFFFFF">HN :: <y><?=$rows['hn']?></y></td>
<td width="258" align="left" bgcolor="#FFFFFF">VN Or AN :: <y><?=$rows['vn']?></y></td>
</tr>
<tr>
<td width="151" align="left" bgcolor="#FFFFFF">คำนำหน้าชื่อ :: <y><?=$rows['pname']?></y></td>
<td width="155" align="left" bgcolor="#FFFFFF">ชื่อ :: <y><?=$rows['fname']?></y></td>
<td align="left" bgcolor="#FFFFFF">นามสกุล :: <y><?=$rows['lname']?></y></td>
</tr>
<tr>
<td colspan=3 align="Center" bgcolor="#FFFFFF">รับจาก ::
<label for="textfield">
<y><?=get_Wdname($rows['wardAC'])?></y>
</label></td>
</tr>
<tr>
<td align="left" bgcolor="#FFFFFF">สิ่งที่ต้องการ ::</td>
<td colspan="2" bgcolor="#FFFFFF"><y><?=get_WtOC($rows['WantOC'])?>
<?=get_WtWC($rows['WantWC'])?>
<?=get_WtB($rows['WantWB'])?>
<?=get_WtBB($rows['WantBB'])?></y></td>
</tr>
<tr>
<td align="left" bgcolor="#FFFFFF">อุปกรณ์ ::</td>
<td colspan="2" bgcolor="#FFFFFF"><y>
<?=get_TlN($rows['TollN'])?>
<?=get_TlOG($rows['TollOG'])?>
<?=get_TlSL($rows['TollSL'])?>
</y></td>
</tr>
<tr>
<td align="left" bgcolor="#FFFFFF">ชื่อผู้รับ ::</td>
<td colspan="2" bgcolor="#FFFFFF"><y>
<div align="left">
<input type="text" name="Showname_2" id="Showname_2" value=""/>
<input type="submit" name="button_1" id="button_1" value="รับการร้องขอ" onclick="javascript:popup('statusCradle.php','',660,500); submit()"/>
</div>
</y></td>
</tr>
<tr>
<td colspan="3" align="center" bgcolor="#FFFFFF"><input type="submit" name="button" id="button" style="width:88px;height:32px"value="ตกลง" /></td>
</tr>
</Table>
<?
} // end loop
?>
</table>
Code ภาพที่ 3
<table align="center" width="520" height="28" border="2">
<caption>::สถานะการดำเนินงานศูนย์เปล::</caption>
<thead>
<tr>
<td width="51"> <div align="center">เลือก </div></td>
<td width="26" >No.</td>
<td width="76">คำนำหน้า </td>
<td width="134">ชื่อ</td>
<td width="134">นามสกุล</td>
<td width="94">สถานะ</td>
</tr>
</thead>
<tbody>
<?php
mysql_connect("","","") or die("error".mysql_error());
mysql_select_db("hotpital");
mysql_query("SET NAMES UTF8");
mysql_query("SET character_set_results=UTF8");
mysql_query("SET character_set_client=UTF8");
mysql_query("SET character_set_connection=UTF8");
$strSQL = "SELECT id,pname,fname,lname FROM cradler";
$resultSQL = mysql_query($strSQL);
while ($rows = mysql_fetch_array($resultSQL)){
$nameselect = "เลือก";
?>
<tr>
<td><a href="#" class="backlink" rel="<?php echo $rows['pname']," ",$rows['fname']," ",$rows['lname']; ?>"><?=$nameselect?></a></td>
<td><?=$rows['id']?></td>
<td><?=$rows['pname']?></td>
<td><?=$rows['fname']?></td>
<td><?=$rows['lname']?></td>
<td></td>
</tr>
<?
} // end loop
?>
</tbody>
</table>
Tag : PHP, MySQL, HTML/CSS, JavaScript, jQuery

|
|
 |
 |
 |
 |
Date :
2013-09-06 09:26:04 |
By :
The_Colosseum |
View :
2458 |
Reply :
6 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code ภาพที่ 3
ปรับบรรทัดที่ 23 เป็น
Code (PHP)
$strSQL = "SELECT id,pname,fname,lname,status FROM cradler"; //คิวรี่ตัวแปร status เพิ่มขึ้นมา
เอาบรรทัดที่ 35 ออกเอาบรรทัดนี้ไปลงแทน
Code (PHP)
<td>
<? if($rows['status ']=='1'){ echo "กำลังดำเนินการ" } else { ?>
<a href="showRequest.php?autoid=<?=$rows['autoid']?>" target="_blank">รับ</a>
<? }?>
</td>
ปล. ถ้าสถานะมีมากกว่า 2 รูปแบบเช่น รอ กำลังดำเนินการ เสร็จสิ้น ก็ให้เป็น else เป็น else if ตามด้วยเงื่อนใขตัวเลขสถานะที่ต้องการ
|
 |
 |
 |
 |
Date :
2013-09-06 10:27:25 |
By :
meannerss |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
นั้นเหละครับมันมี 2 ส่วนให้พิจารณา
1. ส่วนการ update ข้อมูลเมื่อกดปุ่มรับของ id นี้ เอาหละมาไล่กัน
1.1 Code (PHP)
<a href="showRequest.php?autoid=<?=$rows['autoid']?>" target="_blank">รับ</a>
เมื่อผู้ใช้กดปุ่มรับมีการส่งตัวแปรGET autoid ไปยังไฟล์ showRequest.php
1.2 เปิดไฟล์ showRequest (เข้าใจว่าภาพที่2) ขึ้นมาทำการพิจารณา เราจะเห็นได้ว่าอ่อ เราจะปรับเปลี่ยน status เมื่อกดปุ่ม ตกลงแล้วนะ
Code (PHP)
<input type="submit" name="button" id="button" style="width:88px;height:32px"value="ตกลง" />
1.3 แล้วจะทำยังไงให้เกิดการ update เมื่อมีปุ่มตกลง การกดปุ่มตาลงมันต้องส่ง $_POST ไช่มั้ย มันต้องมี action ก่อนจริงไหมค่อยจะส่ง post ได้ เราก็เอา action ดังด้านล่างนี้ไปติดไว้ใต้ BODY
Code (PHP)
<form id="form1" name="form1" method="post" action="">
1.4 เมื่อไส่ค่าได้แล้วเราก็เริ่มเงื่อนใขที่จะทำการ update เมื่อกดตกลง
Code (PHP)
<?
if($_POST)
{
//เริ่มทำ SQL การอัพเดท
}
?>
2. ส่วนการนำข้อมูลมาแสดง >> ส่วนนี้ทำตาม No. 1
|
 |
 |
 |
 |
Date :
2013-09-06 10:58:04 |
By :
meannerss |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ท่าน ทั้งหลายอยู่ไหมเอ่ยยย
|
 |
 |
 |
 |
Date :
2013-09-06 13:35:47 |
By :
The_Colosseum |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 01
|