03.
<head>
04.
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=UTF-8"
/>
05.
<title>Untitled Document</title>
06.
</head>
07.
08.
<body>
09.
<?php
10.
$host
=
"localhost"
;
11.
$db_username
=
"root"
;
12.
$db_password
=
"1234"
;
13.
$dbname
=
"project-smileit"
;
14.
mysql_connect(
$host
,
$db_username
,
$db_password
);
15.
$sql
=
"select * from products p, type t where p.pro_type_id=t.Type_id"
;
16.
mysql_query(
"SET NAMES utf8"
);
17.
$result
=mysql_db_query(
$dbname
,
$sql
);
18.
print
"<table width=100% border=1>"
;
19.
print
"<th>รหัสสินค้า</th>"
;
20.
print
"<th>ชื่อสินค้า</th>"
;
21.
print
"<th>ราคาสินค้า</th>"
;
22.
print
"<th>รูปภาพสินค้า</th>"
;
23.
print
"<th>ประเภทสินค้า</th>"
;
24.
print
"<th>Edit</th>"
;
25.
print
"<th>Delete</th>"
;
26.
while
(
$row
=mysql_fetch_array(
$result
)){
27.
print
"<tr>"
;
28.
print
"<td align=center>$row[Pro_id] </td>"
;
29.
print
"<td>$row[Proname] </td>"
;
30.
print
"<td>$row[Price] </td>"
;
31.
print
"<td align=center><img src=$row[pro_image] width=200 height=200></td>"
;
32.
print
"<td align=center>$row[Type_name] </td>"
;
33.
print
"<td align=center><a href=editpro.php?proid=$row[Pro_id]>แก้ไข</a></td>"
;
34.
print
"<td align=center><a href=showproduct.php?proid=$row[Pro_id]>ลบ</a></td>"
;
35.
print
"</tr>"
;
36.
}
37.
print
"</table>"
;
38.
$id
=
$_GET
[proid];
39.
if
(
$id
<>
""
){
40.
$sqldel
=
"delete from products where Pro_id='$proid'"
;
41.
$resultdel
=mysql_db_query(
$dbname
,
$sqldel
);
42.
if
(
$resultdel
){
43.
echo
"<script>alert('ลบข้อมูลเรียบร้อยแล้ว')</script>"
;
44.
echo
"<meta http-equiv='refesh' content='0;URL=showproduct.php'>"
;
45.
}
else
{
46.
echo
"<script>alert('ไม่สามารถลบข้อมูลได้')</script>"
;
47.
}
48.
}
49.
?>
50.
</body>
51.
</html>