Tải bản đầy đủ (.doc) (3 trang)

bài tập thực hành thương mai điện tử số 3 - tạo trang danh mục sản phẩm

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (114.43 KB, 3 trang )

Bài tập Thực hành Thương mại điện tử
Bài tập thực hành số 3
+ Tổng số buổi thực hành là 1 buổi, mỗi buổi 2 tiết
+ Hình thức báo cáo sau các buổi thực hành: Sinh viên làm bài trên máy và nộp cho giáo
viên hướng dẫn ở buổi thứ 2, trong thư mục mang tên sinh viên
+ Nghiêm cấm mọi sao chép bài làm của nhau, nếu bị phát hiện sẽ được KHÔNG được thi
Bài số 1.
Ôn tập:
- Cài đặt webserver và kiểm tra IIS.
- Truyền dữ liệu từ form
- Truyền dữ liệu từ CSDL
- Tạo tập tin danh mục sản phẩm
Tạo CSDL có tên “db.mdb” với bảng “Categories” và các trường như sau:
catcode Catdes catname catimage
1 Nokia Mobile Nokia <img src="anh/nokia.gif">
2 Samsung Mobile Samsung <img src="anh/samsung.gif">
3 Motorola Mobile Motorola <img src="anh/motorola.gif">
4 Sony Mobile Sony <img src="anh/sony.gif">
Tạo liên kết với CSDL như sau:
Tạo tập tin "db.inc" như sau
<%
dim db
dim strConn
strConn="Driver={Microsoft Access Driver (*.mdb)}; DBQ="&Server.MapPath("db.mdb")
Set db = Server.CreateObject("ADODB.Connection")
db.open strConn
%>
Hiển thị CSDL trên trang web:
<%@ LANGUAGE = "VBScript" %>
<! #include file="db.inc" >
<%


dim rs
set rs=db.execute("select * from categories")
%>
<table border="1" width="100%">
<tr>
<%for each x in rs.Fields%>
<th><%Response.Write(x.name)%></th>
<%next%>
</tr>
<%do until rs.EOF%>
<tr>
<%for each x in rs.Fields%>
<td><%Response.Write(x.value)%></td>
<%next
rs.MoveNext%>
</tr>
<%loop
rs.close
db.close
Bài tập Thực hành Thương mại điện tử
%>
</table>
Bài số 2.
Hiển thị Danh mục trên trang web với dạng ảnh:
<%@ LANGUAGE = "VBScript" %>
<! #include file="db.inc" >
<%
dim rs
set rs=db.execute("select * from categories")
%>

<table width="15%">
<tr>
<th>PRODUCT CATEGORY</th>
</tr>
<%do until rs.EOF%>
<tr>
<td><%Response.Write(rs("catimage"))%></td>
<%
rs.MoveNext%>
</tr>
<%loop
rs.close
db.close
%>
</table>
Bài số 3
Trong CSDL “db.mdb” tạo bảng “Products” và các trường như sau:
Productid name description price image catcode notes featured
1 Nokia 7250i <img src="anh/n7250i.jpg"> 1 yes
2
Nokia 6820 <img src="anh/n6820.jpg"> 1 no
3 Samsung X600 <img src="anh/ssx600.gif"> 2 no
4
Motorola V690 <img src="anh/v690.gif"> 3 yes
5 SonyEricson P800 <img src="anh/p800.gif"> 4 yes
Tạo liên kết với CSDL
Hiển thị bảng “Products’ trên trang web (tự làm)
Bài số 4
Mở rộng bài số 2: với mỗi danh mục, tạo một liên kết đến danh sách sản phẩm thuộc danh
mục đó. Mỗi sản phẩm liên kết đến trang “product.asp”

Tập tin có tên là “category.asp”
<%@ LANGUAGE = "VBScript" %>
<! #include file="db.inc" >
<%
dim catcode
catcode=request.querystring("catcode")
%>
<html>
<body>
<%
if len(catcode)=0 then
dim rs
Bài tập Thực hành Thương mại điện tử
set rs=db.execute("select * from categories")
%>
<table width="15%">
<tr>
<th>PRODUCT CATEGORY</th>
</tr>
<%do until rs.EOF%>
<tr>
<td>
<a href='category.asp?catcode=<%= rs("catcode") %>' style="text-
decoration:none;"><%=rs("catimage") %>
</td>
<%
rs.MoveNext%>
</tr>
<%loop
rs.close

db.close
%>
</table>
<%else
set rscat=db.execute("select * from categories where catcode=" & catcode)
set rscatlist=db.execute("select name,productid from products where catcode=" & catcode & "
order by name")
%>
<font face="helvetica" size="3" ><B><%= rscat("catname") %></B></font><br>
<% if not rscatlist.eof then
rscatlist.movefirst
while not rscatlist.eof
%>
<font size="1" face="helvetica" >
<a href='product.asp?productid=<%= rscatlist("productid")%>'><
%=rscatlist("name")%></a>
<br>
<%
rscatlist.movenext
wend
end if
end if
%>
</body>
</html>

×