<html> <head> <meta charset="utf-8"> <title>ThaiCreate.Com PHP & MySQL Tutorial</title> </head> <body> <script language="JavaScript"> function onDelete() { if(confirm('Do you want to delete ?')==true) { return true; } else { return false; } } </script> <script type="text/javascript"> function checkform() { var checkvar = document.frmMain.elements['chk[]']; var checked = false; for (var i = 0; i < checkvar.length; i++) { if (checkvar[i].checked==true){ checked = true; } } if (checked == true){ return true; } else { alert('เลือกสักอันสิ'); return false; } } </script> <form name="frmMain" action="phpMySQLDeleteMultiRecord.php" method="post"> <?php require_once("clsConnection2.php"); $conn = new Connection(); $strSQL = "SELECT * FROM customer"; $objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]"); ?> <table width="600" border="1"> <tr> <th width="91"> <div align="center">CustomerID </div></th> <th width="91"> <div align="center">ProductID </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> <th width="30"> <div align="center">Delete </div></th> </tr> <?php $i=0; $j=0; while($objResult = mysql_fetch_array($objQuery)) { $i++; $j++; ?> <tr> <td><div align="center"><?php echo $objResult["CustomerID"];?></div></td> <td><div align="center"><?php echo $objResult["ProductID"];?></div></td> <td><?php echo $objResult["Name"];?></td> <td><?php echo $objResult["Email"];?></td> <td><div align="center"><?php echo $objResult["CountryCode"];?></div></td> <td align="right"><?php echo $objResult["Budget"];?></td> <td align="right"><?php echo $objResult["Used"];?></td> <td align="center"> <input type="checkbox" name="chkDel[]" id="chkDel<?php echo $i;?>" value="<?php echo $objResult["CustomerID"];?>"> <input type="hidden" name="type[]" id="type<?php echo $i;?>" value="<?php echo $objResult["ProductID"];?>"> </td> </tr> <?php } ?> </table> <input type="submit" name="btnDelete" value="Delete" onClick="checkform()"> </form> </body> </html>
<html> <head> <title>ThaiCreate.Com PHP & MySQL Tutorial</title> </head> <body> <?php require_once("clsConnection2.php"); $conn = new Connection(); for($i=0;$i<count($_POST["chkDel"]);$i++) { if($_POST["chkDel"][$i] != "") { $strSQL = "DELETE FROM customer "; $strSQL .="WHERE CONVERT( `customer`.`CustomerID` USING utf8 ) = '".$_POST["chkDel"][$i]."' "; $strSQL .="and CONVERT( `customer`.`ProductID` USING utf8 )= '".$_POST["type"][$i]."' "; $objQuery = mysql_query($strSQL); echo $strSQL; } } //echo "Record Deleted."; ?> </body> </html>
WHERE CustomerID = '".$_POST["chkDel"][$i]."'
<html> <head> <meta charset="utf-8"> <title>ThaiCreate.Com PHP & MySQL Tutorial</title> </head> <body> <?php require_once("clsConnection2.php"); $conn = new Connection(); for($i=0;$i<count($_POST["chkDel"]);$i++) { if($_POST["chkDel"][$i] != "") { $strSQL = "DELETE FROM customer "; $strSQL .="WHERE CustomerID = '".$_POST["chkDel"][$i]."' "; $strSQL .="AND ProductID '".$_POST["type"][$i]."' "; $objQuery = mysql_query($strSQL); echo $strSQL; } } //echo "Record Deleted."; ?> </body> </html>
<input type="checkbox" name="chkDel[]" id="chkDel<?php echo $i;?>" value="<?php echo ($i-1);?>"> <input type="hidden" name="CusID[]" id="CusID<?php echo $i;?>" value="<?php echo $objResult["CustomerID"];?>"> <input type="hidden" name="type[]" id="type<?php echo $i;?>" value="<?php echo $objResult["ProductID"];?>">
<html> <head> <meta charset="utf-8"> <title>ThaiCreate.Com PHP & MySQL Tutorial</title> </head> <body> <?php require_once("clsConnection2.php"); $conn = new Connection(); for($i=0;$i<count($_POST["chkDel"]);$i++) { if($_POST["chkDel"][$i] != "") { $id = $_POST["chkDel"][$i]; $strSQL = "DELETE FROM customer "; $strSQL .="WHERE CustomerID = '".$_POST["CusID"][$id]."' "; $strSQL .="AND ProductID '".$_POST["type"][$id]."' "; $objQuery = mysql_query($strSQL); echo $strSQL; } } //echo "Record Deleted.";Code (PHP) ?> </body> </html>
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง