001.
<html>
002.
<head>
003.
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
004.
</head>
005.
<body>
006.
<script language=
"JavaScript"
>
007.
function
ClickCheckAll(vol)
008.
{
009.
010.
var
i=1;
011.
for
(i=1;i<=document.frmMain.hdnCount.value;i++)
012.
{
013.
if
(vol.checked ==
true
)
014.
{
015.
eval(
"document.frmMain.chkDel"
+i+
".checked=true"
);
016.
}
017.
else
018.
{
019.
eval(
"document.frmMain.chkDel"
+i+
".checked=false"
);
020.
}
021.
}
022.
}
023.
024.
function
onDelete()
025.
{
026.
027.
var
i=1;
028.
var
iChk=0;
029.
for
(i=1;i<=document.frmMain.hdnCount.value;i++)
030.
{
031.
var
chk = document.getElementById(
"chkDel"
+i);
032.
if
(chk.checked==
true
)
033.
{
034.
iChk++;
035.
}
036.
}
037.
038.
if
(iChk==0)
039.
{
040.
alert(
'Please select less than one line.'
);
041.
return
false
;
042.
}
043.
044.
if
(confirm(
'Do you want to delete ?'
)==
true
)
045.
{
046.
return
true
;
047.
}
048.
else
049.
{
050.
return
false
;
051.
}
052.
}
053.
</script>
054.
<form name=
"frmMain"
action=
"phpMySQLDeleteMultiRecord.php"
method=
"post"
OnSubmit=
"return onDelete();"
>
055.
<?
056.
$objConnect = mysql_connect(
"localhost"
,
"root"
,
"root"
) or die(
"Error Connect to Database"
);
057.
$objDB = mysql_select_db(
"mydatabase"
);
058.
$strSQL =
"SELECT * FROM customer"
;
059.
$objQuery = mysql_query($strSQL) or die (
"Error Query ["
.$strSQL.
"]"
);
060.
?>
061.
<table width=
"600"
border=
"1"
>
062.
<tr>
063.
<th width=
"91"
> <div align=
"center"
>CustomerID </div></th>
064.
<th width=
"98"
> <div align=
"center"
>Name </div></th>
065.
<th width=
"198"
> <div align=
"center"
>Email </div></th>
066.
<th width=
"97"
> <div align=
"center"
>CountryCode </div></th>
067.
<th width=
"59"
> <div align=
"center"
>Budget </div></th>
068.
<th width=
"71"
> <div align=
"center"
>Used </div></th>
069.
<th width=
"30"
> <div align=
"center"
>
070.
<input name=
"CheckAll"
type=
"checkbox"
id=
"CheckAll"
value=
"Y"
onClick=
"ClickCheckAll(this);"
>
071.
</div></th>
072.
</tr>
073.
<?
074.
$i = 0;
075.
while
($objResult = mysql_fetch_array($objQuery))
076.
{
077.
$i++;
078.
?>
079.
<tr>
080.
<td><div align=
"center"
><?=$objResult[
"CustomerID"
];?></div></td>
081.
<td><?=$objResult[
"Name"
];?></td>
082.
<td><?=$objResult[
"Email"
];?></td>
083.
<td><div align=
"center"
><?=$objResult[
"CountryCode"
];?></div></td>
084.
<td align=
"right"
><?=$objResult[
"Budget"
];?></td>
085.
<td align=
"right"
><?=$objResult[
"Used"
];?></td>
086.
<td align=
"center"
>
087.
<input type=
"checkbox"
name=
"chkDel[]"
id=
"chkDel<?=$i;?>"
value=
"<?=$objResult["
CustomerID
"];?>"
>
088.
</td>
089.
</tr>
090.
<?
091.
}
092.
?>
093.
</table>
094.
<?
095.
mysql_close($objConnect);
096.
?>
097.
<input type=
"submit"
name=
"btnDelete"
value=
"Delete"
>
098.
<input type=
"hidden"
name=
"hdnCount"
value=
"<?=$i;?>"
>
099.
</form>
100.
</body>
101.
</html>