Bước 1: Thiết kế lại Database + Trong bảng theloai và theloaitin hãy thêm vào một trường linkngoai, kiểu dữ liệu là INT + Tại trường url hay diachilink hãy nhập vào địa chỉ Link ngòai
Trang 1Trung Tâm Đào Tạo Công Nghệ Mạng VIỆT CHUYÊN
740/12 Sư Vạn Hạnh (nối dài), P12, Q10, TP.HCM Tel: (84.8) 862 7509 – (84.8) 2649179
Email: traning@vietchuyen.org Website: www.vietchuyen.org – www.ddcntt.vn
Biên soạn: Nguyễn Phát Tài
LAB – SOTHINK DYNAMIC MENU
+ Trong bài thực hành này chúng ta sẽ xuất dữ liệu động từ database ra Menu (2 cấp)
+ Để là được bài LAB này bạn nên xem lại bài LAB trong sách giáo trình trước khi qua phần này
Bước 1: Thiết kế lại Database
+ Trong bảng theloai và theloaitin hãy thêm vào một trường linkngoai, kiểu dữ liệu là INT
+ Tại trường url hay diachilink hãy nhập vào địa chỉ Link ngòai cho thể lọai nào cần Link ra ngòai ví
dụ như trong menu của bạn có một Menu Yahoo thì url sẽ là http://www.yahoo.com, còn các tin tức
bên torng site thì chỗ địa chỉ này sẽ để trống
Bước 2: Sửa lại đọan Code do menu Sothink phát sinh ra như sau:
<script id="sothink_widgets:dwwidget_dhtmlmenu4_12_2008.pgt" type="text/javascript">
<!
stm_bm(["menu0244",850,"","blank.gif",0,"","",0,0,250,0,20,1,0,0,"","",0,0,1,1,"default","hand",""],this);
stm_bp("p0",[1,4,0,0,0,1,10,0,100,"",-2,"",-2,50,0,0,"#999999","transparent","bg_01.gif",3,0,0,"#000000"]);
<?php
$dbhost = "localhost"; // DB Host name
$dbusername = "root"; // DB User
$dbpass = "vc111!!!"; // DB User password
$dbname = "cms"; // DB Name
$query = "select * from theloai where visiblemenu=1"; // bang the loai chinh
$connection = mysql_connect($dbhost, $dbusername, $dbpass);
$resultCat = mysql_db_query($dbname, $query);
$numrowsCat = mysql_num_rows($resultCat);
for ($i = 0; $i < $numrowsCat; $i++)
{
$rowCat = mysql_fetch_array($resultCat);
$CatName = $rowCat["tentheloai"]; //ten the loai chinh
if($rowCat["linkngoai"]==1)
{
$Link= $rowCat["url"]; //dia chi link cua menu
}
else
{
$Link= "index.php?mod=newscategory&ID_theloai=".$rowCat["ID_theloai"];
}
$Tip= $rowCat["tip"]; //chu thich cua menu
?>
stm_ai("p0i0",[1," <b><?php echo $CatName?></b>","","",-1,-1,0,"<?php echo $Link?>","_self","<?php
echo
$Tip?>","","icon_57.gif","icon_56.gif",10,10,0,"","",-1,-1,0,0,1,"#FFFFF7",1,"#B5BED6",1,"Page%201_r9_c19.jpg","Page%201_r13_c55.jpg",3,3,0,0,"#FFFFF7","#000
000","#000000","#669966","8pt 'Arial','Verdana'","8pt 'Arial','Verdana'",0,0],150,23);
stm_bpx("p1","p0",[1,2,0,2,0,0,11,0,80,"progid:DXImageTransform.Microsoft.RandomDissolve(,enabled=0,Durati
on=0.30)",12,"progid:DXImageTransform.Microsoft.RandomDissolve(,enabled=0,Duration=0.30)",12,80,0,0,"#66
6666","#000000","",3,1,1]);
<?php
$queryPro = "select * from theloaitin where visiblemenu=1 and ID_theloai=".$rowCat["ID_theloai"];
CHUYÊN
Trang 2Trung Tâm Đào Tạo Công Nghệ Mạng VIỆT CHUYÊN
740/12 Sư Vạn Hạnh (nối dài), P12, Q10, TP.HCM Tel: (84.8) 862 7509 – (84.8) 2649179
Email: traning@vietchuyen.org Website: www.vietchuyen.org – www.ddcntt.vn
Biên soạn: Nguyễn Phát Tài
$resultPro = mysql_db_query($dbname, $queryPro);
$numrowsPro = mysql_num_rows($resultPro);
for ($j = 0; $j<$numrowsPro; $j++)
{
$rowPro = mysql_fetch_array($resultPro);
$ProName = $rowPro["tentheloaitin"]; //ten the loai tin cap 2
if($rowPro["linkngoai"]==1)
{
$Link = $rowPro["diachilink"]; // dia chi link cap 2
}
else
{
$Link= "index.php?mod=newssubcategory&ID_theloai=".$rowPro["ID_theloai"]."&ID_theloaitin=".$rowPro["ID_theloaitin"];
}
$Chuthich = $rowPro["chuthich"]; //chu thich cua cap 2
?>
stm_ai("p0i0",[1," <b><?php echo $ProName?></b>","","",-1,-1,0,"<?php echo $Link?>","_self","<?php
echo
$Chuthich?>","","icon_57.gif","icon_56.gif",10,10,0,"","",-1,-1,0,0,1,"#FFFFF7",1,"#B5BED6",1,"Page%201_r9_c19.jpg","Page%201_r13_c55.jpg",3,3,0,0,"#FFFFF7","#000
000","#000000","#669966","8pt 'Arial','Verdana'","8pt 'Arial','Verdana'",0,0],172,23);
<?php
}
?>
stm_ep();
<?php
}
?>
stm_ep();
stm_em();
// >
</script>
Hãy chú ý các đọan Code màu đỏ là chúng ta thêm vào để xử lý thêm cho việc khi click vào Link
ngoài và Link trong
CHUYÊN