Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > ถามเพิ่มเติม เกี่ยวกับเพิ่ม/แก้ไข/ลบ ข้อมูลใน Form เดียวกัน คล้าย ๆ กับ DataGrid หรือ GridView



 

ถามเพิ่มเติม เกี่ยวกับเพิ่ม/แก้ไข/ลบ ข้อมูลใน Form เดียวกัน คล้าย ๆ กับ DataGrid หรือ GridView

 



Topic : 101493



โพสกระทู้ ( 7 )
บทความ ( 0 )



สถานะออฟไลน์




จากกระทู้
PHP MySQL Add/Insert/Edit/Delete to MySQL On Same Form เป็นตัวอย่างการเขียน PHP & MySQL ให้สามารถ เพิ่ม/แก้ไข/ลบ ข้อมูลใน Form เดียวกัน คล้าย ๆ กับ DataGrid หรือ GridView

https://www.thaicreate.com/php/php-mysql-add-insert-edit-delete-mysql-same-form.html

เราจะสลับผลลัพธ์ยังไง ที่จากเดิมคือ (การเพิ่มข้อมูลจะอยู่ "ด้านล่าง" สุดเสมอ)
SELECT
INSERT

เป็น (อยากการเพิ่มข้อมูลให้อยู่ "ด้านบน"สุดเสมอ)
INSERT
SELECT

พอจะเข้าใจคำถามนู๋มั้ยCode (PHP)
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>compressor</title></head>
<body>
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("db_siamair");

//*** Add Condition ***//
if($_POST["hdnCmd"] == "Add")
{
	$strSQL = "INSERT INTO compressor ";
	$strSQL .="(com_id,category_id,com_category_id,brand_id,com_name,refrig_id,model,com_distinction,com_amount,unit_id,com_cost,com_price,com_image,com_note) ";
	$strSQL .="VALUES ";
	$strSQL .="('".$_POST["txtAddcom_id"]."','".$_POST["selAddcategory"]."' ";
	$strSQL .=",'".$_POST["selAddcom_category"]."' ";
	$strSQL .=",'".$_POST["selAddbrand"]."','".$_POST["txtAddcom_name"]."' ";
	$strSQL .=",'".$_POST["selAddrefrig"]."','".$_POST["txtAddmodel"]."' ";
	$strSQL .=",'".$_POST["txtAddcom_distinction"]."','".$_POST["txtAddcom_amount"]."' ";	
	$strSQL .=",'".$_POST["selAddunit"]."','".$_POST["txtAddcom_cost"]."' ";
	$strSQL .=",'".$_POST["txtAddcom_price"]."','".$_POST["txtAddcom_image"]."' ";	
	$strSQL .=",'".$_POST["txtAddcom_note"]."') ";
	$objQuery = mysql_query($strSQL);
	if(!$objQuery)
	{
		echo "Error Save [".mysql_error()."]";
	}
	//header("location:$_SERVER[PHP_SELF]");
	//exit();
}

//*** Update Condition ***//
if($_POST["hdnCmd"] == "Update")
{
	$strSQL = "UPDATE compressor SET ";
	$strSQL .="com_id 				= '".$_POST["txtEditcom_id"]."' ";
	$strSQL .=",category_id		 	= '".$_POST["selEditcategory"]."' ";
	$strSQL .=",com_category_id		= '".$_POST["selEditcom_category"]."' ";
	$strSQL .=",brand_id		 	= '".$_POST["selEditbrand"]."' ";
	$strSQL .=",com_name 			= '".$_POST["txtEditbrand_name"]."' ";
	$strSQL .=",refrig_id 			= '".$_POST["txtEditbrand_name"]."' ";
	$strSQL .=",model 				= '".$_POST["txtEditbrand_name"]."' ";
	$strSQL .=",com_distinction		= '".$_POST["txtEditbrand_name"]."' ";
	$strSQL .=",com_amount 			= '".$_POST["txtEditbrand_name"]."' ";
	$strSQL .=",unit_id				= '".$_POST["txtEditbrand_name"]."' ";
	$strSQL .=",com_cost 			= '".$_POST["txtEditbrand_name"]."' ";
	$strSQL .=",com_price 			= '".$_POST["txtEditbrand_name"]."' ";
	$strSQL .=",com_image 			= '".$_POST["txtEditbrand_name"]."' ";
	$strSQL .=",com_note			= '".$_POST["txtEditbrand_name"]."' ";
		
	$strSQL .="WHERE com_id = '".$_POST["hdnEditcom_id"]."' ";
	$objQuery = mysql_query($strSQL);
	if(!$objQuery)
	{
		echo "Error Update [".mysql_error()."]";
	}
	//header("location:$_SERVER[PHP_SELF]");
	//exit();
}

//*** Delete Condition ***//
if($_GET["Action"] == "Del")
{
	$strSQL = "DELETE FROM compressor ";
	$strSQL .="WHERE com_id = '".$_GET["comID"]."' ";
	$objQuery = mysql_query($strSQL);
	if(!$objQuery)
	{
		echo "Error Delete [".mysql_error()."]";
	}
	//header("location:$_SERVER[PHP_SELF]");
	//exit();
}

$strSQL = "SELECT * FROM(compressor INNER JOIN category ON compressor.category_id=category.category_id) INNER JOIN brand ON compressor.brand_id = brand.brand_id INNER JOIN compressor_category ON compressor.com_category_id = compressor_category.com_category_id INNER JOIN refrigerant ON compressor.refrig_id = refrigerant.refrig_id INNER JOIN unit ON compressor.unit_id = unit.unit_id";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$num_rows = mysql_num_rows($objQuery);
$i=0;
?>
<form name="frmMain" method="post" action="<?=$_SERVER["PHP_SELF"];?>">
<input type="hidden" name="hdnCmd" value="">
<table width="600" border="1">
  <tr>
	<th width="34"> <div align="center">รหัส </div></th>
	<th width="120"> <div align="center">สภาพ</div></th>
	<th width="134"> <div align="center">ยี่ห้อคอม</div></th>
	<th width="83"> <div align="center">ยี่ห้อรถยนต์</div></th>
	<th width="125"> <div align="center">ชื่อคอม</div></th>
	<th width="82"> <div align="center">ใช้กับน้ำยา</div></th>
	<th width="120"> <div align="center">รุ่นรถยนต์</div></th>
	<th width="198"> <div align="center">ลักษณะพิเศษคอม</div></th>
	<th width="50"> <div align="center">จำนวน</div></th>
	<th width="81"> <div align="center">หน่วย</div></th>
	<th width="44"> <div align="center">ต้นทุน</div></th>
	<th width="30"> <div align="center">ขาย</div></th>
	<th width="120"> <div align="center">รูปภาพ</div></th>
	<th width="161"> <div align="center">หมายเหตุ</div></th>
	<th width="31"> <div align="center">Edit </div></th>
	<th width="49"> <div align="center">Delete </div></th>
  </tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
   <tr>
	<td><div align="center"><input type="text" name="txtAddcom_id" size="1"></div></td>
	<td><label>
	  <select name="selAddcategory">
			 <option value="" selected> --เลือก--</option>
			 <? 
			 $strSQL = "SELECT * FROM category";
			 $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
			 while($objResult = mysql_fetch_array($objQuery)){
		  ?>
			 <option value="<?=$objResult[category_id]?>">
			 <?=$objResult[category_name]?>
			 </option>
			 <?
			 }
			   ?>
		</select></label>
	</td>
	<td><label>
	  <select name="selAddcom_category">
			 <option value="" selected> --เลือก--</option>
			 <? 
			 $strSQL = "SELECT * FROM compressor_category";
			 $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
			 while($objResult = mysql_fetch_array($objQuery)){
		  ?>
			 <option value="<?=$objResult[com_category_id]?>">
			 <?=$objResult[com_category_name]?>
			 </option>
			 <?
			 }
			   ?>
	 </select></label>
	</td>
	<td>
	<label>
	  <select name="selAddbrand">
			 <option value="" selected> --เลือก--</option>
			 <? 
			 $strSQL = "SELECT * FROM brand";
			 $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
			 while($objResult = mysql_fetch_array($objQuery)){
		  ?>
			 <option value="<?=$objResult[brand_id]?>">
			 <?=$objResult[brand_name]?>
			 </option>
			 <?
			 }
			   ?>
	 </select></label>
	</td>
	
	<td><input type="text" name="txtAddcom_name" size="10"></td>
	
	<td><label>
	  <select name="selAddrefrig">
			 <option value="" selected> --เลือก--</option>
			 <? 
			 $strSQL = "SELECT * FROM refrigerant";
			 $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
			 while($objResult = mysql_fetch_array($objQuery)){
		  ?>
			 <option value="<?=$objResult[refrig_id]?>">
			 <?=$objResult[refrig_name]?>
			 </option>
			 <?
			 }
			   ?>
	 </select></label>
	 </td>
	<td><input type="text" name="txtAddmodel" size="20"></td>
	<td><input type="text" name="txtAddcom_distinction" size="10"></td>
	<td><input name="txtAddcom_amount" type="text" size="1"></td>
	<td><label>
	  <select name="selAddunit">
			 <option value="" selected> --เลือก--</option>
			 <? 
			 $strSQL = "SELECT * FROM unit ORDER BY unit_id desc";
			 $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
			 while($objResult = mysql_fetch_array($objQuery)){
		  ?>
			 <option value="<?=$objResult[unit_id]?>" selected >
			 <?=$objResult[unit_name]?>
			 </option>
			 <?
			 }
			   ?>
	 </select></label></td>
	<td><input type="text" name="txtAddcom_cost" size="5"></td>
	<td><input type="text" name="txtAddcom_price" size="5"></td>
	<td><input type="text" name="txtAddcom_image" size="20"></td>
	<td><textarea name="txtAddcom_note" cols="" rows="2"></textarea></td>
	<td colspan="2" align="right"><div align="center">
	  <input name="btnAdd" type="button" id="btnAdd" value="Add" OnClick="frmMain.hdnCmd.value='Add';frmMain.submit();">
	</div></td>
  </tr>
  
  
  <?
	if($objResult["com_id"] == $_GET["comID"] and $_GET["Action"] == "Edit")
	{
  ?>
  <tr>
  <? // OPEN EDIT?>
  
	<td><div align="center">
		<input type="text" name="txtEditcom_id" size="5" value="<?=$objResult["com_id"];?>">
		<input type="hidden" name="hdnEditcom_id" size="5" value="<?=$objResult["com_id"];?>">
	</div></td>
   <td><label>
		<select name="selEditcategory">
		<option value=""></option>
			 <? 
			 $strSQL2 = "SELECT * FROM category";
			 $objQuery2 = mysql_query($strSQL2) or die ("Error Query [".$strSQL2."]");
			 while($objResult2 = mysql_fetch_array($objQuery2)){
			 if ($objResult2[category_id]==$objResult[category_id]){
			 ?>
			 <option value="<?=$objResult2[category_id]?>" selected><?=$objResult2[category_name]?></option>
			 <?
		 } else {
			 ?>
			  <option value="<?=$objResult2[category_id]?>"><?=$objResult2[category_name]?></option>
			 <?
			 }
			 }
			   ?>
		 </select></label>
	</td>
	<td><label>
	  <select name="selEditcom_category">
			 <option value="" selected> --เลือก--</option>
			 <? 
			 $strSQL2 = "SELECT * FROM compressor_category";
			 $objQuery2 = mysql_query($strSQL2) or die ("Error Query [".$strSQL2."]");
			 while($objResult2 = mysql_fetch_array($objQuery2)){
			 if ($objResult2[com_category_id]==$objResult[com_category_id]){
			 ?>
			 <option value="<?=$objResult2[com_category_id]?>" selected><?=$objResult2[com_category_name]?></option>
			 <?
		 } else {
			 ?>
			  <option value="<?=$objResult2[com_category_id]?>"><?=$objResult2[com_category_name]?></option>
			 <?
			 }
			 }
			   ?>
	 </select></label>
	</td>
	<td>
	<label>
	  <select name="selEditbrand">
			 <option value="" selected> --เลือก--</option>
			 <? 
			 $strSQL2 = "SELECT * FROM brand";
			 $objQuery2 = mysql_query($strSQL2) or die ("Error Query [".$strSQL2."]");
			 while($objResult2 = mysql_fetch_array($objQuery2)){
			 if ($objResult2[brand_id]==$objResult[brand_id]){
			 ?>
			 <option value="<?=$objResult2[brand_id]?>" selected><?=$objResult2[brand_name]?></option>
			 <?
		 } else {
			 ?>
			  <option value="<?=$objResult2[brand_id]?>"><?=$objResult2[brand_name]?></option>
			 <?
			 }
			 }
			   ?>
	 </select></label>
	</td>
	
	<td><input type="text" name="txtEditcom_name" size="10"  value="<?=$objResult["com_name"];?>"></td>
	
	<td><label>
	  <select name="selEditrefrig">
			 <option value="" selected> --เลือก--</option>
			 <? 
			 $strSQL2 = "SELECT * FROM refrigerant";
			 $objQuery2 = mysql_query($strSQL2) or die ("Error Query [".$strSQL2."]");
			 while($objResult2 = mysql_fetch_array($objQuery2)){
			if ($objResult2[refrig_id]==$objResult[refrig_id]){
			 ?>
			 <option value="<?=$objResult2[refrig_id]?>" selected><?=$objResult2[refrig_name]?></option>
			 <?
		 } else {
			 ?>
			  <option value="<?=$objResult2[refrig_id]?>"><?=$objResult2[refrig_name]?></option>
			 <?
			 }
			 }
			   ?>
	 </select></label>
	 </td>
	<td><input type="text" name="txtEditmodel" size="20" value="<?=$objResult["model"];?>"></td>
	<td><input type="text" name="txtEditcom_distinction" size="10" value="<?=$objResult["com_distinction"];?>"></td>
	<td><input name="txtEditcom_amount" type="text" size="1" value="<?=$objResult["com_amount"];?>"></td>
	<td><label>
	  <select name="selEditunit">
			 <option value="" selected> --เลือก--</option>
			 <? 
			 $strSQL2 = "SELECT * FROM unit ";
			 $objQuery2 = mysql_query($strSQL2) or die ("Error Query [".$strSQL2."]");
			 while($objResult2 = mysql_fetch_array($objQuery2)){
			 if ($objResult2[unit_id]==$objResult[unit_id]){
			 ?>
			 <option value="<?=$objResult2[unit_id]?>" selected><?=$objResult2[unit_name]?></option>
			 <?
		 } else {
			 ?>
			  <option value="<?=$objResult2[unit_id]?>"><?=$objResult2[unit_name]?></option>
			 <?
			 }
			 }
			   ?>
	 </select></label></td>
	<td><input type="text" name="txtEditcom_cost" size="5" value="<?=number_format($objResult["com_cost"]);?>.00"></td>
	<td><input type="text" name="txtEditcom_price" size="5" value=" <?=number_format($objResult["com_price"]);?>.00"></td>
	<td><input type="text" name="txtEditcom_image" size="20" value="<?=$objResult["com_image"];?>"></td>
	<td><textarea name="txtEditcom_note" cols="" rows="2" value="<?=$objResult["com_note"];?>"></textarea></td>
	
	
	
	<td colspan="2" align="right"><div align="center">
	  <input name="btnAdd" type="button" id="btnUpdate" value="Update" OnClick="frmMain.hdnCmd.value='Update';frmMain.submit();">
	  <input name="btnAdd" type="button" id="btnCancel" value="Cancel" OnClick="window.location='<?=$_SERVER["PHP_SELF"];?>';">
	</div></td>
  </tr>
  <?
	}
  else
	{
  ?>
  <? // CLOSE EDIT?>
  <? // OPEN SELECT?>
  <tr>
   <td><div align="center"><?=$objResult["com_id"];?></div></td>
   <td><?=$objResult["category_name"];?></td>
   <td><?=$objResult["com_category_name"];?></td>
   <td><?=$objResult["brand_name"];?></td>
   <td><?=$objResult["com_name"];?></td>
   <td><?=$objResult["refrig_name"];?></td>
   <td><?=$objResult["model"];?></td>
   <td><?=$objResult["com_distinction"];?></td>
   <td><?=$objResult["com_amount"];?></td>
   <td><?=$objResult["unit_name"];?></td>
   <td><?=number_format($objResult["com_cost"]);?>.00</td>
   <td><?=number_format($objResult["com_price"]);?>.00</td>
   <td><?=$objResult["com_images"];?></td>
   <td><?=$objResult["com_note"];?></td>
  
	<td align="center"><a href="<?=$_SERVER["PHP_SELF"];?>?Action=Edit&comID=<?=$objResult["com_id"];?>">Edit</a></td>
	<td align="center"><a href="JavaScript:if(confirm('Confirm Delete?')==true){window.location='<?=$_SERVER["PHP_SELF"];?>?Action=Del&comID=<?=$objResult["com_id"];?>';}">Delete</a></td>
  </tr>
  <?
	}
  ?>
<?
}
?>
<? // close SELECT?>
<? // OPEN ADD?>
  
</table>
<? // close ADD?>
</form>
<?
mysql_close($objConnect);
?>
</body>
</html>



ผลลัพธ์จากโค้ด
ตาราง
ทำการย้ายแถวเพิ่มข้อมูลไปไว้ข้างบนแล้ว แถวแสดงขอมูลก็ไม่ยอมแสดงข้อมูล



Tag : PHP









ประวัติการแก้ไข
2013-10-09 14:55:04
2013-10-09 14:57:57
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-10-09 14:44:28 By : buatong301 View : 1076 Reply : 1
 

 

No. 1



โพสกระทู้ ( 7 )
บทความ ( 0 )



สถานะออฟไลน์


แสดงแล้วค่ะ แต่!!!! เมื่อกด UPDATE ข้อมูลในฐานข้อมูลก็เปลี่ยนค่าไปค่ะ


ค่า


Code (PHP)
<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>compressor</title></head>
<body>
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("db_siamair");

//*** Add Condition ***//
if($_POST["hdnCmd"] == "Add")
{
	$strSQL = "INSERT INTO compressor ";
	$strSQL .="(com_id,category_id,com_category_id,brand_id,com_name,refrig_id,model,com_distinction,com_amount,unit_id,com_cost,com_price,com_image,com_note) ";
	$strSQL .="VALUES ";
	$strSQL .="('".$_POST["txtAddcom_id"]."','".$_POST["selAddcategory"]."' ";
	$strSQL .=",'".$_POST["selAddcom_category"]."' ";
	$strSQL .=",'".$_POST["selAddbrand"]."','".$_POST["txtAddcom_name"]."' ";
	$strSQL .=",'".$_POST["selAddrefrig"]."','".$_POST["txtAddmodel"]."' ";
	$strSQL .=",'".$_POST["txtAddcom_distinction"]."','".$_POST["txtAddcom_amount"]."' ";	
	$strSQL .=",'".$_POST["selAddunit"]."','".$_POST["txtAddcom_cost"]."' ";
	$strSQL .=",'".$_POST["txtAddcom_price"]."','".$_POST["txtAddcom_image"]."' ";	
	$strSQL .=",'".$_POST["txtAddcom_note"]."') ";
	$objQuery = mysql_query($strSQL);
	if(!$objQuery)
	{
		echo "Error Save [".mysql_error()."]";
	}
	//header("location:$_SERVER[PHP_SELF]");
	//exit();
}

//*** Update Condition ***//
if($_POST["hdnCmd"] == "Update")
{
	$strSQL = "UPDATE compressor SET ";
	$strSQL .="com_id 				= '".$_POST["txtEditcom_id"]."' ";
	$strSQL .=",category_id		 	= '".$_POST["selEditcategory"]."' ";
	$strSQL .=",com_category_id		= '".$_POST["selEditcom_category"]."' ";
	$strSQL .=",brand_id		 	= '".$_POST["selEditbrand"]."' ";
	$strSQL .=",com_name 			= '".$_POST["txtEditbrand_name"]."' ";
	$strSQL .=",refrig_id 			= '".$_POST["txtEditbrand_name"]."' ";
	$strSQL .=",model 				= '".$_POST["txtEditbrand_name"]."' ";
	$strSQL .=",com_distinction		= '".$_POST["txtEditbrand_name"]."' ";
	$strSQL .=",com_amount 			= '".$_POST["txtEditbrand_name"]."' ";
	$strSQL .=",unit_id				= '".$_POST["txtEditbrand_name"]."' ";
	$strSQL .=",com_cost 			= '".$_POST["txtEditbrand_name"]."' ";
	$strSQL .=",com_price 			= '".$_POST["txtEditbrand_name"]."' ";
	$strSQL .=",com_image 			= '".$_POST["txtEditbrand_name"]."' ";
	$strSQL .=",com_note			= '".$_POST["txtEditbrand_name"]."' ";
		
	$strSQL .="WHERE com_id = '".$_POST["hdnEditcom_id"]."' ";
	$objQuery = mysql_query($strSQL);
	if(!$objQuery)
	{
		echo "Error Update [".mysql_error()."]";
	}
	//header("location:$_SERVER[PHP_SELF]");
	//exit();
}

//*** Delete Condition ***//
if($_GET["Action"] == "Del")
{
	$strSQL = "DELETE FROM compressor ";
	$strSQL .="WHERE com_id = '".$_GET["comID"]."' ";
	$objQuery = mysql_query($strSQL);
	if(!$objQuery)
	{
		echo "Error Delete [".mysql_error()."]";
	}
	//header("location:$_SERVER[PHP_SELF]");
	//exit();
}

?>
<form name="frmMain" method="post" action="<?=$_SERVER["PHP_SELF"];?>">
<input type="hidden" name="hdnCmd" value="">
<table width="600" border="1">
  <tr>
    <th width="34"> <div align="center">รหัส </div></th>
    <th width="120"> <div align="center">สภาพ</div></th>
	<th width="134"> <div align="center">ยี่ห้อคอม</div></th>
	<th width="83"> <div align="center">ยี่ห้อรถยนต์</div></th>
	<th width="125"> <div align="center">ชื่อคอม</div></th>
	<th width="82"> <div align="center">ใช้กับน้ำยา</div></th>
	<th width="120"> <div align="center">รุ่นรถยนต์</div></th>
	<th width="198"> <div align="center">ลักษณะพิเศษคอม</div></th>
	<th width="50"> <div align="center">จำนวน</div></th>
	<th width="81"> <div align="center">หน่วย</div></th>
	<th width="44"> <div align="center">ต้นทุน</div></th>
	<th width="30"> <div align="center">ขาย</div></th>
	<th width="120"> <div align="center">รูปภาพ</div></th>
	<th width="161"> <div align="center">หมายเหตุ</div></th>
    <th width="31"> <div align="center">Edit </div></th>
    <th width="49"> <div align="center">Delete </div></th>
  </tr>
  
  <tr>
    <td><div align="center"><input type="text" name="txtAddcom_id" size="1"></div></td>
	<td><label>
	  <select name="selAddcategory">
             <option value="" selected> --เลือก--</option>
             <? 
   			 $strSQL = "SELECT * FROM category";
 			 $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
 			 while($objResult = mysql_fetch_array($objQuery)){
 		  ?>
             <option value="<?=$objResult[category_id]?>">
             <?=$objResult[category_name]?>
             </option>
             <?
  			 }
 			   ?>
        </select></label>
	</td>
	<td><label>
	  <select name="selAddcom_category">
             <option value="" selected> --เลือก--</option>
             <? 
   			 $strSQL = "SELECT * FROM compressor_category";
 			 $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
 			 while($objResult = mysql_fetch_array($objQuery)){
 		  ?>
             <option value="<?=$objResult[com_category_id]?>">
             <?=$objResult[com_category_name]?>
             </option>
             <?
  			 }
 			   ?>
	 </select></label>
	</td>
	<td>
	<label>
	  <select name="selAddbrand">
             <option value="" selected> --เลือก--</option>
             <? 
   			 $strSQL = "SELECT * FROM brand";
 			 $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
 			 while($objResult = mysql_fetch_array($objQuery)){
 		  ?>
             <option value="<?=$objResult[brand_id]?>">
             <?=$objResult[brand_name]?>
             </option>
             <?
  			 }
 			   ?>
	 </select></label>
	</td>
	
	<td><input type="text" name="txtAddcom_name" size="10"></td>
	
	<td><label>
	  <select name="selAddrefrig">
             <option value="" selected> --เลือก--</option>
             <? 
   			 $strSQL = "SELECT * FROM refrigerant";
 			 $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
 			 while($objResult = mysql_fetch_array($objQuery)){
 		  ?>
             <option value="<?=$objResult[refrig_id]?>">
             <?=$objResult[refrig_name]?>
             </option>
             <?
  			 }
 			   ?>
	 </select></label>
	 </td>
	<td><input type="text" name="txtAddmodel" size="20"></td>
	<td><input type="text" name="txtAddcom_distinction" size="10"></td>
	<td><input name="txtAddcom_amount" type="text" size="1"></td>
    <td><label>
	  <select name="selAddunit">
             <option value="" selected> --เลือก--</option>
             <? 
   			 $strSQL = "SELECT * FROM unit ORDER BY unit_id desc";
 			 $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
 			 while($objResult = mysql_fetch_array($objQuery)){
 		  ?>
             <option value="<?=$objResult[unit_id]?>" selected >
             <?=$objResult[unit_name]?>
             </option>
             <?
  			 }
 			   ?>
	 </select></label></td>
    <td><input type="text" name="txtAddcom_cost" size="5"></td>
    <td><input type="text" name="txtAddcom_price" size="5"></td>
	<td><input type="text" name="txtAddcom_image" size="20"></td>
    <td><textarea name="txtAddcom_note" cols="" rows="2"></textarea></td>
    <td colspan="2" align="right"><div align="center">
      <input name="btnAdd" type="button" id="btnAdd" value="Add" OnClick="frmMain.hdnCmd.value='Add';frmMain.submit();">
    </div></td>
  </tr>
  
 <? $strSQL = "SELECT * FROM(compressor INNER JOIN category ON compressor.category_id=category.category_id) INNER JOIN brand ON compressor.brand_id = brand.brand_id INNER JOIN compressor_category ON compressor.com_category_id = compressor_category.com_category_id INNER JOIN refrigerant ON compressor.refrig_id = refrigerant.refrig_id INNER JOIN unit ON compressor.unit_id = unit.unit_id";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$num_rows = mysql_num_rows($objQuery);
$i=0;
?>

<?
while($objResult = mysql_fetch_array($objQuery))
{
?>

  <?
	if($objResult["com_id"] == $_GET["comID"] and $_GET["Action"] == "Edit")
	{
  ?>
  <tr>
  <? // OPEN EDIT?>
  
    <td><div align="center">
		<input type="text" name="txtEditcom_id" size="5" value="<?=$objResult["com_id"];?>">
		<input type="hidden" name="hdnEditcom_id" size="5" value="<?=$objResult["com_id"];?>">
	</div></td>
   <td><label>
		<select name="selEditcategory">
  		<option value=""></option>
			 <? 
   			 $strSQL2 = "SELECT * FROM category";
 			 $objQuery2 = mysql_query($strSQL2) or die ("Error Query [".$strSQL2."]");
 			 while($objResult2 = mysql_fetch_array($objQuery2)){
			 if ($objResult2[category_id]==$objResult[category_id]){
 		 	 ?>
             <option value="<?=$objResult2[category_id]?>" selected><?=$objResult2[category_name]?></option>
			 <?
 		 } else {
 			 ?>
			  <option value="<?=$objResult2[category_id]?>"><?=$objResult2[category_name]?></option>
             <?
  			 }
			 }
 			   ?>
   	 	 </select></label>
	</td>
	<td><label>
	  <select name="selEditcom_category">
             <option value="" selected> --เลือก--</option>
             <? 
   			 $strSQL2 = "SELECT * FROM compressor_category";
 			 $objQuery2 = mysql_query($strSQL2) or die ("Error Query [".$strSQL2."]");
 			 while($objResult2 = mysql_fetch_array($objQuery2)){
			 if ($objResult2[com_category_id]==$objResult[com_category_id]){
 		 	 ?>
             <option value="<?=$objResult2[com_category_id]?>" selected><?=$objResult2[com_category_name]?></option>
			 <?
 		 } else {
 			 ?>
			  <option value="<?=$objResult2[com_category_id]?>"><?=$objResult2[com_category_name]?></option>
             <?
  			 }
			 }
 			   ?>
	 </select></label>
	</td>
	<td>
	<label>
	  <select name="selEditbrand">
             <option value="" selected> --เลือก--</option>
             <? 
   			 $strSQL2 = "SELECT * FROM brand";
 			 $objQuery2 = mysql_query($strSQL2) or die ("Error Query [".$strSQL2."]");
 			 while($objResult2 = mysql_fetch_array($objQuery2)){
			 if ($objResult2[brand_id]==$objResult[brand_id]){
 		 	 ?>
             <option value="<?=$objResult2[brand_id]?>" selected><?=$objResult2[brand_name]?></option>
			 <?
 		 } else {
 			 ?>
			  <option value="<?=$objResult2[brand_id]?>"><?=$objResult2[brand_name]?></option>
             <?
  			 }
			 }
 			   ?>
	 </select></label>
	</td>
	
	<td><input type="text" name="txtEditcom_name" size="10"  value="<?=$objResult["com_name"];?>"></td>
	
	<td><label>
	  <select name="selEditrefrig">
             <option value="" selected> --เลือก--</option>
             <? 
   			 $strSQL2 = "SELECT * FROM refrigerant";
 			 $objQuery2 = mysql_query($strSQL2) or die ("Error Query [".$strSQL2."]");
 			 while($objResult2 = mysql_fetch_array($objQuery2)){
			if ($objResult2[refrig_id]==$objResult[refrig_id]){
 		 	 ?>
             <option value="<?=$objResult2[refrig_id]?>" selected><?=$objResult2[refrig_name]?></option>
			 <?
 		 } else {
 			 ?>
			  <option value="<?=$objResult2[refrig_id]?>"><?=$objResult2[refrig_name]?></option>
             <?
  			 }
			 }
 			   ?>
	 </select></label>
	 </td>
	<td><input type="text" name="txtEditmodel" size="20" value="<?=$objResult["model"];?>"></td>
	<td><input type="text" name="txtEditcom_distinction" size="10" value="<?=$objResult["com_distinction"];?>"></td>
	<td><input name="txtEditcom_amount" type="text" size="1" value="<?=$objResult["com_amount"];?>"></td>
    <td><label>
	  <select name="selEditunit">
             <option value="" selected> --เลือก--</option>
             <? 
   			 $strSQL2 = "SELECT * FROM unit ";
 			 $objQuery2 = mysql_query($strSQL2) or die ("Error Query [".$strSQL2."]");
 			 while($objResult2 = mysql_fetch_array($objQuery2)){
			 if ($objResult2[unit_id]==$objResult[unit_id]){
 		 	 ?>
             <option value="<?=$objResult2[unit_id]?>" selected><?=$objResult2[unit_name]?></option>
			 <?
 		 } else {
 			 ?>
			  <option value="<?=$objResult2[unit_id]?>"><?=$objResult2[unit_name]?></option>
             <?
  			 }
			 }
 			   ?>
	 </select></label></td>
    <td><input type="text" name="txtEditcom_cost" size="5" value="<?=number_format($objResult["com_cost"]);?>.00"></td>
    <td><input type="text" name="txtEditcom_price" size="5" value=" <?=number_format($objResult["com_price"]);?>.00"></td>
	<td><input type="text" name="txtEditcom_image" size="20" value="<?=$objResult["com_image"];?>"></td>
    <td><textarea name="txtEditcom_note" cols="" rows="2" value="<?=$objResult["com_note"];?>"></textarea></td>
	
	
	
    <td colspan="2" align="right"><div align="center">
      <input name="btnAdd" type="button" id="btnUpdate" value="Update" OnClick="frmMain.hdnCmd.value='Update';frmMain.submit();">
	  <input name="btnAdd" type="button" id="btnCancel" value="Cancel" OnClick="window.location='<?=$_SERVER["PHP_SELF"];?>';">
    </div></td>
  </tr>
  <?
	}
  else
	{
  ?>
  <? // CLOSE EDIT?>
  <? // OPEN SELECT?>
  <tr>
   <td><div align="center"><?=$objResult["com_id"];?></div></td>
   <td><?=$objResult["category_name"];?></td>
   <td><?=$objResult["com_category_name"];?></td>
   <td><?=$objResult["brand_name"];?></td>
   <td><?=$objResult["com_name"];?></td>
   <td><?=$objResult["refrig_name"];?></td>
   <td><?=$objResult["model"];?></td>
   <td><?=$objResult["com_distinction"];?></td>
   <td><?=$objResult["com_amount"];?></td>
   <td><?=$objResult["unit_name"];?></td>
   <td><?=number_format($objResult["com_cost"]);?>.00</td>
   <td><?=number_format($objResult["com_price"]);?>.00</td>
   <td><?=$objResult["com_images"];?></td>
   <td><?=$objResult["com_note"];?></td>
  
    <td align="center"><a href="<?=$_SERVER["PHP_SELF"];?>?Action=Edit&comID=<?=$objResult["com_id"];?>">Edit</a></td>
	<td align="center"><a href="JavaScript:if(confirm('Confirm Delete?')==true){window.location='<?=$_SERVER["PHP_SELF"];?>?Action=Del&comID=<?=$objResult["com_id"];?>';}">Delete</a></td>
  </tr>
  <?
	}
  ?>
<?
}
?>
<? // close SELECT?>
<? // OPEN ADD?>
  
</table>
<? // close ADD?>
</form>
<?
mysql_close($objConnect);
?>
</body>
</html>


2



เจอล่ะค่ะ ยังไม่ได้แก้โค้ด Update ^^








ประวัติการแก้ไข
2013-10-09 15:09:08
2013-10-09 16:27:26
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-10-09 15:03:17 By : buatong301
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ถามเพิ่มเติม เกี่ยวกับเพิ่ม/แก้ไข/ลบ ข้อมูลใน Form เดียวกัน คล้าย ๆ กับ DataGrid หรือ GridView
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 00
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่