PHP VAØ DATABASE
9-2
COMPUTER LEARNING CENTER
WWW.HUUKHANG.COM
Hình 10-1: Lieät keâ danh saùch laïi saûn phaåm
Ñeå cho pheùp laáy ñöôïc nhieàu giaù trò choïn cuûa saûn phaåm nhö hình tren, baïn khai baùo caùc checkbox
naøy cuøng teân (giaû söû teân laø chkid) vaø giaù trò trò laø SubCateID cuûa moãi saûn phaåm nhö ví duï 10-1
trong trang lietke.php.
<?php
if($totalRows>0)
{
$i=0;
while ($row = mysql_fetch_array ($result))
{
$i+=1;
?>
<tr valign="top">
<td><input type=checkbox name=chkid
value="<?=$row["SubCateID"]?>"> </td>
<td><?=$row["CateID"]?>
</td>
<td><?=$row["SubCateID"]?> </td>
<td ><a href="capnhat.php?id=<?=$row["SubCateID"]?>">
<?=$row["SubCateName"]?></a></td>
</tr>
<?php
}
?>
<tr
valign="top">
<td colspan="4" align="middle">
<hr noshade size="1">
</td>
</tr>
<tr
valign="top">
<td colspan=3><input type=submit value="Delete">
<input type=hidden name=from_ value="subcategories">
<input type=hidden name=type value="0">
<input type=hidden name=chon value="">
<input type=button value="New"
onclick="window.open('them.php',target='_main')"></td>
<td >Tong so mau tin <?=$i?></td>
</tr>
<?php
}else{
?>
<tr valign="top">
<td > </td><td > </td><td > </td>
<td > <b><font face="Arial" color="#FF0000">
Oop! Ship not found!</font></b></td>
</tr>
<?php
}
?>
Trong ñoù, hai khai baùo sau:
<input type=hidden name=from_ value="subcategories">
<input type=hidden name=type value="0">
<input type=hidden name=chon value="">
Cho bieát baïn submit töø trang naøo vaø loaïi xoaù nhieàu maåu tin hay moät maåu tin ñoái vôùi baûng töông
öùng. Muïc ñích cuûa vaán ñeà naøy laø trang delete söû duïng chung cho nhieàu baûng khaùc nhau vaø töø trang
lieät keâ (xoaù nhieàu) hoaëc töø trang edit (1 maåu tin cuï theå).
Ngoaøi ra, chuùng ta khai baùo <input type=hidden name=chon value=""> ñeå nhaän giaù trò choïn treân
caùch checkbox baèng caùch khai baùo ñoaïn javascript nhö sau:
<script>
function
calculatechon()