|
|
|
ช่วยทีคับ Checkbox ไม่ตรงกับที่เลือกคับ ผิดพลาดขออภัยด้วยนะคับ โพสครั้งแรกคับ |
|
|
|
|
|
|
|
Code (PHP)
if($_GET["action"]=="add")
{
$sql1 = "select buy_id from buy order by buy_id DESC limit 1 ";
$result1 = mysql_query($sql1);
while($dbarr1 = mysql_fetch_row($result1))
{
$stresID= (int)substr("000$dbarr1[0]", -3);
$stresID = $stresID+1;
$buyID = "b".substr("000$stresID", -3);
}
$Date1 = $_POST['txtdate'];
$Date2 = $_POST['txtDate2'];
//-------------------------------------- Substring Start ----------------------------
$Sdateex = explode('/',$Date1);
$Date1 = $Sdateex[0];
$SMonth = $Sdateex[1];
$SYear = $Sdateex[2]-543;
$Sdate2 = $SYear."-01-01";
$Date1 = $SYear."-".$SMonth."-".$Date1;
//--------------------------------------- Substring End -----------------------------
$Edateex = explode('/',$Date2);
$Date2 = $Edateex[0];
$EMonth = $Edateex[1];
$EYear = $Edateex[2]-543;
$EYear2 = $EYear."-12-31";
$Date2 = $EYear."-".$EMonth."-".$Date2;
$sum=0;
$n=0;
count($_POST["chk"]);
for($i=0;$i<count($_POST["amt"]);$i++)
{
if($_POST["chk"][$i] != ""){
$po_id1 =$_POST["chk"][$i];
}
if($_POST["chk"][$i] !=""){
$n++;
$mat_amt = $_POST["amt"][$i];
$mat_id = $_POST['txt_id'][$i];
$sup_id = $_POST['selectsup'];
$sum+=$mat_amt;
$sql = "insert into buy_detail Values ('$buyID','$n','$mat_amt','$mat_id','')";
mysql_query("SET NAMES UTF8");
$dbquery = mysql_query($sql);
/*echo $sql2 = "update devices set d_num=d_num-$device_amt where d_id='$d_id'";
mysql_query("SET NAMES UTF8");
$dbquery = mysql_query($sql2);*/
}
}
$sql12 = "insert into buy Values ('$buyID','".date("Y-m-d")."','','$sup_id','ยังไม่ได้รับ','$sum','')";
mysql_query("SET NAMES UTF8");
$dbquery12 = mysql_query($sql12);
$_SESSION["buy_id"]=$buyID;
echo" <script type='text/javascript'>
alert('บันทึกข้อมูลเรียบร้อย');
window.location='buy_mat.php';
</script>";
}
?>
<body>
<p><? include "header.php"; ?>
<table width="978" height="756" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="178" height="753" align="left" valign="top" bgcolor="#FFFFFF"><? include "menu.php"; ?><td width="710" valign="top" bgcolor="#FFFFFF"><p><br />
<br />
</p>
<form name="add" action="?action=add" method="post">
<table width="655" border="1" align="center" cellpadding="2" cellspacing="2">
<tr>
<td height="31" colspan="6" align="center" bgcolor="#0056B1"><font color="#FFFFFF">ข้อมูลสั่งซื้อวัตถุดิบ</font></td>
</tr>
<tr>
<td colspan="2" align="right" bgcolor="#DDE5F0">วันที่</td>
<?
$Date3 = date("Y-m-d");
//-------------------------------------- Substring Start ----------------------------
$Sdateex3 = explode('-',$Date3);
$Date3 = $Sdateex3[2];
$SMonth3 = $Sdateex3[1];
$SYear3 = $Sdateex3[0]+543;
$Sdate2 = $SYear3."-01-01";
$Date3 = $Date3."/".$SMonth3."/".$SYear3;
?>
<td height="13" colspan="4" align="left" valign="middle" bgcolor="#DDE5F0"><?=$Date3;?></td>
</tr>
<tr>
<td colspan="2" align="right" bgcolor="#DDE5F0">ผู้จำหน่ายอาหาร </td>
<td height="14" colspan="4" align="left" valign="middle" bgcolor="#DDE5F0"><select name="selectsup" id="select">
<?
$sql6 = "select sup_id,sup_name
FROM supplier";
$result6 = mysql_query($sql6);
while($dbarr6 = mysql_fetch_row($result6))
{
?>
<option value="<?=$dbarr6[0]?>">
<?=$dbarr6[1]?>
</option>
<?
}
?>
</select></td>
</tr>
<tr>
<td height="26" colspan="6" align="center" bgcolor="#FFFFFF"></td>
</tr>
<tr>
<td height="12" colspan="6" align="center" bgcolor="#0056B1"><font color="#FFFFFF">ข้อมูลวัตถุดิบถึงจุดสั่งซื้อ</font></td>
</tr>
<tr>
<td width="37" height="5" align="center" bgcolor="#98C6EA">เลือก</td>
<td width="150" align="center" bgcolor="#98C6EA">สี</td>
<td width="100" height="5" align="center" bgcolor="#98C6EA">จำนวนต่ำสุด</td>
<td width="100" align="center" bgcolor="#98C6EA">จำนวนสูงสุด</td>
<td width="100" align="center" bgcolor="#98C6EA">จำนวนคงเหลือ</td>
<td width="100" align="center" bgcolor="#98C6EA">สั่งซื้อจำนวน</td>
</tr>
<?
$Date1 = $_POST['txtdate'];
$Date2 = $_POST['txtDate2'];
//-------------------------------------- Substring Start ----------------------------
$Sdateex = explode('/',$Date1);
$Date1 = $Sdateex[0];
$SMonth = $Sdateex[1];
$SYear = $Sdateex[2]-543;
$Sdate2 = $SYear."-01-01";
$Date1 = $SYear."-".$SMonth."-".$Date1;
//--------------------------------------- Substring End -----------------------------
$Edateex = explode('/',$Date2);
$Date2 = $Edateex[0];
$EMonth = $Edateex[1];
$EYear = $Edateex[2]-543;
$EYear2 = $EYear."-12-31";
$Date2 = $EYear."-".$EMonth."-".$Date2;
?>
<?
$sql="select mat_id,mat_name,mat_minstock,mat_maxstock,mat_stock,(mat_maxstock-mat_stock) total from material where mat_stock<=mat_minstock and mat_id not in (select mat_id from buy_detail,buy where buy.buy_id=buy_detail.buy_id and buy_status='ยังไม่ได้รับ')";
$result = mysql_query($sql);
while($dbarr = mysql_fetch_row($result))
{
?>
<tr>
<td height="1" align="center" bgcolor="#DDE5F0"><input type="checkbox" name="chk[]" id="checkbox" value="<?=$dbarr[0]?>"/></td>
<td height="1" align="center" bgcolor="#DDE5F0"><?=$dbarr[1]?><input type="hidden" name="txt_id[]" id="textfield2" size="15" value="<?=$dbarr[0]?>"/></td>
<td width="144" height="1" align="center" bgcolor="#DDE5F0"><?=$dbarr[2]?></td>
<td width="82" align="center" bgcolor="#DDE5F0"><?=$dbarr[3]?></td>
<td width="95" align="center" bgcolor="#DDE5F0"><?=$dbarr[4]?></td>
<td width="90" align="center" bgcolor="#DDE5F0"><label for="textfield2"></label>
<input type="text" name="amt[]" size="15" id="textfield2" value="<?=$dbarr[5]?>" /></td>
</tr>
<?
}
?>
<tr>
<td colspan="6" align="center" bgcolor="#98C6EA"><input type="submit" name="button2" id="button2" value="ยืนยันการสั่งซื้อวัตถุดิบ" />
<input type="reset" name="button" id="button" value="ยกเลิกการสั่งซื้อ" /><input type="button" name="button3" id="button3" value="พิมพ์ใบสั่งซื้อวัตถุดิบ" onClick="window.open('purchase order.php','_blank');" /></td>
</tr>
</table>
<p> </p>
</form>
<p> </p></td>
</tr>
<tr>
<td height="3" colspan="2"></td>
</tr>
</table>
<p><? include "footer.php"; ?> </p>
</body>
</html>
<?
ขออภัยด้วยนะคับ ผมเพิ่งหัดใช้
ตอนแรกเลือกสีขาว
แต่ว่า
สีขาวไม่หาย แต่ว่าเป็นสีแดงที่หายไปคับ
Tag : PHP, MySQL, JavaScript
|
ประวัติการแก้ไข 2012-04-06 00:02:05 2012-04-06 00:03:15 2012-04-06 04:01:13
|
|
|
|
|
Date :
2012-04-06 00:00:14 |
By :
bull-shit |
View :
5832 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
จะบอกว่าแบบนี้ใช้เป็นแบบ Array ไม่ได้ครับ ให้ใช้ id ระบุครับ เช่น checkbox1 , checkbox2 , checkbox3 .....
|
|
|
|
|
Date :
2012-04-06 06:59:54 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ตัวอย่างครับ
Code (PHP)
<form name="frmMain" method="post" action="phpMySQLEditRecord.php?Action=Save">
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">CustomerID </div></th>
<th width="98"> <div align="center">Name </div></th>
<th width="198"> <div align="center">Email </div></th>
<th width="97"> <div align="center">CountryCode </div></th>
<th width="59"> <div align="center">Budget </div></th>
<th width="71"> <div align="center">Used </div></th>
</tr>
<?
$i =0;
while($objResult = mysql_fetch_array($objQuery))
{
$i = $i + 1;
?>
<tr>
<td><div align="center">
<input type="hidden" name="hdnCustomerID<?=$i;?>" size="5" value="<?=$objResult["CustomerID"];?>">
<input type="text" name="txtCustomerID<?=$i;?>" size="5" value="<?=$objResult["CustomerID"];?>">
</div></td>
<td><input type="text" name="txtName<?=$i;?>" size="20" value="<?=$objResult["Name"];?>"></td>
<td><input type="text" name="txtEmail<?=$i;?>" size="20" value="<?=$objResult["Email"];?>"></td>
<td><div align="center"><input type="text" name="txtCountryCode<?=$i;?>" size="2" value="<?=$objResult["CountryCode"];?>"></div></td>
<td align="right"><input type="text" name="txtBudget<?=$i;?>" size="5" value="<?=$objResult["Budget"];?>"></td>
<td align="right"><input type="text" name="txtUsed<?=$i;?>" size="5" value="<?=$objResult["Used"];?>"></td>
</tr>
<?
}
?>
</table>
<input type="submit" name="submit" value="submit">
<input type="hidden" name="hdnLine" value="<?=$i;?>">
</form>
Go to : PHP MySQL Multiple Rows Edit/Update Record
|
|
|
|
|
Date :
2012-04-06 07:01:56 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณมากเลยคับ
|
|
|
|
|
Date :
2012-04-06 12:04:40 |
By :
bull-shit |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|