 |
|
คือเราต้องการที่จะ Update status เล้าไก่ จาก open เป็น close อ่าจ๊ะ โดนจะเปลี่ยนเมื่อมีการ select ข้อมูลเข้าไป เช่น มีการเลี้ยงที่เล้า H4 พอ select เล้า H4 ก็จะเปลี่ยนจาก open เป็น close อ่าจ๊ะ
ตาราง feed=การเลี้ยง กับตาราง Hehhouse = ตาราง เล้าไก่ แล้ว 2 ตารางนี้ มี pen_id เหมือนกัน แต่ พอ select การเลี้ยงใส่ ตาราง feed เสร้จ อยากให้ pen_st = สถานะเนี้ย ที่อยู่ตาราง Hehouse เปลี่ยน เป็น close อ่าจีะ

Code (PHP)
<?
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<?
include("conect.php");
$sf_id = $_POST['txtcmid'] ; //รหัสพนักงาน
$pen_id = $_POST['txtpenid'] ;//รหัสโรงเลี้ยง
$chicken_id = $_POST['txtcid'] ;//รหัสพันธุ์ไก่
$feed_total = $_POST['txttotal'] ;//จำนวนไก่ที่เลี้ยงในเล้า
$f_start = $_POST['date'] ;//วันเริ่มเลี้ยง
if ($sf_id == "") {
?>
<script type="text/javascript">
alert("กรุณากรอกชื่อพนักงานที่เลี้ยง");
history.back();
</script>
<?
}else if ($pen_id == "") {
?>
<script type="text/javascript">
alert("กรุณากรอกรหัสโรงเลี้ยง");
history.back();
</script>
<?
}else if($chicken_id == "") {
?>
<script type="text/javascript">
alert("กรุณากรอกรหัสสายพันธุ์ไก่ที่เลี้ยง");
history.back();
</script>
<?
}else if($feed_total == "") {
?>
<script type="text/javascript">
alert("กรุณากรอกจำนวนไก่ที่เลี้ยง");
history.back();
</script>
<?
}else if($f_start == "") {
?>
<script type="text/javascript">
alert("กรุณากรอกข้อมูลวันเริ่มเลี้ยง");
history.back();
</script>
<?
}else {
?>
<?
$prefix = 'F';
$sq0="SELECT RIGHT(feed_id,2) from feed WHERE LEFT(feed_id, 1) = '$prefix' ORDER BY feed_id DESC LIMIT 1";
$query = mysql_query($sq0) or exit( mysql_error() );
if( $last_id = mysql_result($query, 0) ){
$new_id = $prefix.(substr('00'.++$last_id, -2) );
}else{
$new_id = $prefix.'01';
}
$sql_query=" insert into feed,Hehhouse (feed_id,sf_id,pen_id,chicken_id,feed_total,f_start) values
('$new_id','$sf_id','$pen_id','$chicken_id','$feed_total','$f_start')" ;
$Objquery=mysql_query($sql_query) or die( mysql_error() );
}
?>
<style type="text/css">
body,td,th {
font-family: "Courier New", Courier, monospace;
font-size: 14px;
}
</style>
<tr>
<center>
<table width="50%" border="2" align="center">
<tr>
<th width="27%" scope="row">รหัสพนักงานที่เลี้ยง</th>
<td width="15%" align="center"><? echo $sf_id =$_POST['txtcmid'] ;?> </td>
</tr>
<tr>
<th width="27%" scope="row">รหัสเล้าที่เลี้ยง</th>
<td width="15%" align="center"><? echo $pen_id =$_POST['txtpenid'];?> </td>
</tr>
<tr>
<th width="27%" scope="row">รหัสสายพันธุ์ไก่ที่เลี้ยง</th>
<td width="15%" align="center"><? echo $chicken_id =$_POST['txtcid'] ;?> </td>
</tr>
<tr>
<th width="27%" scope="row">จำนวนไก่ที่เลี้ยง</th>
<td width="15%" align="center"><? echo $feed_total =$_POST['txttotal'] ;?> </td>
</tr>
<tr>
<th width="27%" scope="row">วันที่เริ่มเลี้ยง</th>
<td width="15%" align="center"><? echo $f_start =$_POST['date'];?> </td>
</tr>
<tr>
<th colspan="2" scope="row"><a href="insertfeed.php"><input type="submit" name="back" id="back"value="กลับสู่หน้าหลัก" /></a></th>
</tr>
</table>
</center>
<center>
<?
if($sql_query)
{
echo "บันทึกเรียบร้อยแล้ว";
}
else
{
echo "Error Save [".$sql_query."]";
}
//echo $sql_query;
?>
</center>
</tr>
</body>
</html>
</td>
</tr>
</table>
</td>
</tr>
?>
อันนี้โค้ด saveinsert จ๊ะ
ถ้าใช้โค้ดนี้จะขึ้นไหมอ่าจ๊ะ พอดีจะ ทำเว็ปเพื่อเอาไปใช้ในฟาร์มไก่ของครอบครัว
Code (PHP)
<?
if ($Objquery == "1") {
$sql = "update Hehhouse set pen_st = 'close' where pen_id = '$_POST [txtpenid]' ";
$Objquery=mysql_query($sql) or die( mysql_error() );
}
?>
Tag : PHP, MySQL, HTML/CSS, JavaScript
|
ประวัติการแก้ไข 2013-11-23 19:01:58
|
 |
 |
 |
 |
Date :
2013-11-23 18:45:10 |
By :
lmprovisezii |
View :
823 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |