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 > เช็คค่าซ้ำจาก Array ที่จะเพิ่มลงฐานข้อมูล โดนเพิ่มเป็นแบบ Passing Popup



 

เช็คค่าซ้ำจาก Array ที่จะเพิ่มลงฐานข้อมูล โดนเพิ่มเป็นแบบ Passing Popup

 



Topic : 082412



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



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




ภาพหน้าจอ

คือข้อมูลอะไหล่รถ สามารถเพิ่มได้เรื่อยๆโดยกด + แต่ต้องการ เช็คค่าอะไหล่ที่เลือกมา ไม่ให้ซ้ำกัน รบกวนหน่อยครับ

ถ้าได้ java script ยิ่งดีเลยขอบคุณครับ

Code (PHP)
<html>
<head>
<title>กำหนดอะไหล่รถ</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>

<?
include("config.inc.php");	
$sql = "SELECT * FROM estimate_spare order by id_est";
$query = mysql_query($sql);
?>

<script language="javascript">

	function CreateSelectOption(ele)
	{
		var objSelect = document.getElementById(ele);
		var Item = new Option("", ""); 
		objSelect.options[objSelect.length] = Item;
		<?
		while($result = mysql_fetch_array($query))
		{
		?>
		var Item = new Option("<?=$result["name"];?>", "<?=$result["id_est"];?>"); 
		objSelect.options[objSelect.length] = Item;
		<?
		}
		?>
	}

	function CreateNewRow()
	{
		var intLine = parseInt(document.checkform1.hdnMaxLine.value);
		intLine++;
			
		var theTable = document.getElementById("tbExp");
		var newRow = theTable.insertRow(theTable.rows.length)
		newRow.id = newRow.uniqueID

		var newCell
		
		//*** Column No ***//
		newCell = newRow.insertCell(0);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center>"+intLine+"</center>";

		//*** Column Country Code ***//
		newCell = newRow.insertCell(1);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><SELECT NAME=\"idest"+intLine+"\" ID=\"idest"+intLine+"\"></SELECT></center>";
		//*** Create Option ***//
		CreateSelectOption("idest"+intLine)
		
	
	
		document.checkform1.hdnMaxLine.value = intLine;
	}
	
	function RemoveRow()
	{
		intLine = parseInt(document.checkform1.hdnMaxLine.value);
		if(parseInt(intLine) > 0)
		{
				theTable = document.getElementById("tbExp");				
				theTableBody = theTable.tBodies[0];
				theTableBody.deleteRow(intLine);
				intLine--;
				document.checkform1.hdnMaxLine.value = intLine;
		}	
	}	
	
	function check()
	{			
	for(i=1;i<=document.checkform1.hdnMaxLine.value;i++)
		{
			//*** Column  ***/
			if(eval("document.checkform1.idest"+i+".value")=="")
			{
				alert('กรุณากรอกอะไหล่ลำดับที่ ' + i);
				eval("document.checkform1.idest"+i+".focus();")
				return false;
			}
		}	
	}
	
</script>
<?
if($_POST['submit'] == "")
	{ 
?>	
	
<body OnLoad="CreateNewRow();">

<?
$brand_id = $_GET['brand_id'];
$class_id = $_GET['class_id'];
$type_id = $_GET['type_id'];

$sql = "select a.*,b.*,c.*
from brand a,class b,type c
where a.brand_id = b.brand_id
and b.class_id = c.class_id
and a.brand_id = '$brand_id' and b.class_id = '$class_id' and c.type_id = '$type_id' ";
$query = mysql_query($sql) or die (mysql_error());
$result = mysql_fetch_array($query);

?>
 <form name="checkform1" method="post" action="add_est_car.php" onSubmit="return check();">
<table width="357" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="25" colspan="3"><div align="center"><strong>เพิ่มอะไหล่สำหรับรถ</strong></div></td>
  </tr>

  <tr>
    <td width="127" height="25">ยี่ห้อ</td>
    <td width="129" height="25"><?=$result['brand_name'];?></td>
    <td width="101" height="25">&nbsp;</td>
  </tr>
  <tr>
    <td height="25">รุ่น</td>
    <td height="25"><?=$result['class_name'];?></td>
    <td height="25">&nbsp;</td>
  </tr>
  <tr>
    <td height="25">แบบ</td>
    <td height="25"><?=$result['type_name'];?></td>
    <td height="25">&nbsp;</td>
  </tr>
  <tr>
    <td height="25"><div align="center">
      <input name="btnAdd" type="button" id="btnAdd" value=" + " onClick="CreateNewRow();">
    </div></td>
    <td height="25"><input name="btnDel" type="button" id="btnDel" value=" - " onClick="RemoveRow();"></td>
    <td height="25"><input type=button value="ล้างข้อความ" onClick="javascript:location.reload();" /></td>
  </tr>
  <tr>
    <td height="25">&nbsp;</td>
    <td height="25">&nbsp;</td>
    <td height="25">&nbsp;</td>
  </tr>
</table>

<input name="brand_id" type="hidden" value="<?=$brand_id;?>">
<input name="class_id" type="hidden" value="<?=$class_id;?>">
<input name="type_id" type="hidden" value="<?=$type_id;?>">
<table width="396" border="1" align="center" bordercolor="#000000" id="tbExp">
  <tr>
    <td width="117"><div align="center">ลำดับ</div></td>
    <td width="263"><div align="center">ชื่ออะไหล่</div></td>

  </tr>
</table>
<table width="397" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td colspan="2">&nbsp;</td>
    <td width="198">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2">&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td width="116"><div align="center">
      <input type="hidden" name="hdnMaxLine" value="0">
	 <input type="button" value="ย้อนกลับ" onClick="JavaScript:window.location='f_add_est_car.php';" />
    </div></td>
    <td width="83">&nbsp;</td>
    <td><input type="submit" name="submit" value="เพิ่มข้อมูล"></td>
  </tr>
</table>
<p>&nbsp;</p>
<div align="center">
  <p>&nbsp;</p>
</div>
</form>

<?
}else{  
		//เช็คข้อมูลรถซ้ำ
		$sql = "SELECT * FROM estimate_car WHERE 
		brand_id = '$brand_id' and
		class_id = '$class_id' and
		type_id = '$type_id' ";
		$query = mysql_query($sql) or die (mysql_error());
		$result = mysql_fetch_array($query);
		if($result)
		{ 
	 echo "<script>alert('ข้อมูลรถ ซ้ำโปรดตรวจสอบใหม่อีกครั้ง');window.location='f_add_est_car.php';</script>";

		}else{

		//เพิ่มข้อมูล	
			
		for($i=1;$i<=(int)$_POST["hdnMaxLine"];$i++)
			{			
			$sql1 = " insert into estimate_car (brand_id,class_id,type_id,id_est,status) values 
			('".$_POST['brand_id']."','".$_POST['class_id']."','".$_POST['type_id']."','".$_POST["idest".$i]."','1') ";		
			$query1 = mysql_db_query($dbname,$sql1) or die (mysql_error());					
			}//for
			if($query1)
				{
				echo"<script>alert('บันทึกข้อมูลแล้ว');window.location='f_add_est_car.php';</script>";
				}else{
				echo"<script>alert('ไม่สามารถบันทึกข้อมูลได้');window.location='f_add_est_car.php';</script>";
					 }//else
			   }//else	   	
	  }//else
?>
</body>
</html>





Tag : PHP, MySQL, JavaScript







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-08-16 12:07:23 By : nutsza View : 2435 Reply : 5
 

 

No. 1



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



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


ไม่มีใครตอบเลยเหรอครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-08-16 14:12:41 By : nutsza
 


 

No. 2



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



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


รบกวนหน่อยครับบบ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-08-17 08:15:53 By : nutsza
 

 

No. 3



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

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

JavaScript ยากหน่อยน่ะครับ เพราะคุณจะต้อง Loop แล้วก็ Loop ซ้ำ เพื่อเช็คแต่ล่ะรายการครับ อาจจะต้องใช้ PHP ตรวจสอบน่าจะง่ายกกว่าครับ โดยเก็บข้อมูลลงใน Array จากนั้นก็ใช้พวก in_array() ในการตรวจสอบครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-08-17 14:20:41 By : mr.win
 


 

No. 4



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



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


ตอบความคิดเห็นที่ : 3 เขียนโดย : mr.win เมื่อวันที่ 2012-08-17 14:20:41
รายละเอียดของการตอบ ::
อ่อ ครับพี่วิน พอมีตัวอย่างให้ดูบ้างไหมครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-08-18 08:35:33 By : nutsza
 


 

No. 5



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

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

ไม่มีครับ บอกได้แค่ concept ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-08-18 12:03:08 By : mr.win
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : เช็คค่าซ้ำจาก Array ที่จะเพิ่มลงฐานข้อมูล โดนเพิ่มเป็นแบบ Passing Popup
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 04
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 อัตราราคา คลิกที่นี่