|
ชื่อ
ฐานข้อมูล \db\database.mdb [
Downloads
ฐานข้อมูล ]
ชื่อตาราง Cus_product
ชื่อ Filed
-
ID
- Barcode
- Description
- Price
- Page
- writer

ขั้นที่ 1 ต้องทำ Form เพื่อเลือกรายการที่จะลบข้อมูล
Sample1.php
<html>
<body>
<?
$dsn_name = "database";
$username ="";
$password ="";
$connect_link= odbc_connect($dsn_name, $username,
$password) or die("ติดต่อ DSN ไม่ได้");
$sql = "select * from Cus_product";
$execute = odbc_exec($connect_link, $sql)
or die ("เอ็กซิคิวส์คำสั่งไม่ได้");
?>
<table border="1" width="926">
<tr>
<td width="34">
<div align="center">id</div>
</td>
<td width="101">
<div align="center">barcode</div>
</td>
<td width="293">
<div align="center">description</div>
</td>
<td width="63">
<div align="center">price</div>
</td>
<td width="57">
<div align="center">page</div>
</td>
<td width="282">
<div align="center">writer</div>
</td>
<td width="50">
<div align="center">ลบ</div>
</td>
</tr>
</table>
<?
$i=1;
while(odbc_fetch_row($execute,$i))
{
$id=odbc_result($execute,"id");
$barcode=odbc_result($execute,"barcode");
$description=odbc_result($execute,"description");
$price=odbc_result($execute,"price");
$page=odbc_result($execute,"page");
$writer=odbc_result($execute,"writer");
?>
<table border="1" width="929">
<tr>
<td width="37">
<div align="center">
<? echo "$id"; ?>
</div>
</td>
<td width="96">
<div align="center">
<? echo "$barcode"; ?>
</div>
</td>
<td width="297">
<? echo "$description"; ?>
</td>
<td width="62">
<div align="right">
<? printf ("%.2f",$price);
?>
</div>
</td>
<td width="58">
<div align="right">
<? echo "$page"; ?>
</div>
</td>
<td width="285">
<div align="right">
<? echo "$writer"; ?>
</div>
</td>
<td width="48">
<div align="center"><a
href="Sample2.php?id=<?echo"$id";
?>">ลบ</a></div>
</td>
</tr>
</table>
<?
$i++;
}
?>
<?
odbc_close($connect_link);
?>
</body>
</html>

ขั้นที่ 2 ทำ Form เพื่อลบข้อมูล
Sample2.php
<?
$dsn_name = "database";
$username ="";
$password ="";
$connect_link= odbc_connect($dsn_name, $username,
$password) or die("ติดต่อ DSN ไม่ได้");
$sql = "delete from Cus_product where
id=$id";
$execute = odbc_exec($connect_link, $sql)
or die ("เอ็กซิคิวส์คำสั่งไม่ได้");
odbc_close($connect_link);
echo"ได้ทำการ ลบข้อมูลเรียบร้อยแล้ว
";
?>
out
Put


|