[1012]PHP進階開發及TadTools工具應用
<?php
include_once "header.php";
$parent_gsn=empty($_POST['parent_gsn'])?0:intval($_POST['parent_gsn']);
$gsn=empty($_POST['gsn'])?0:intval($_POST['gsn']);
if(!empty($gsn)){
echo get_contact($gsn);
}else{
echo get_cate_options($parent_gsn);
}
function get_cate_options($parent_gsn){
global $xoopsDB ;
$sql = "select `gsn` , `title` from `".$xoopsDB->prefix("contact_cate")."` where `parent_gsn` = '$parent_gsn' order by `sort`";
$result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'] , 3, mysql_error());
$main="";
while(list($gsn , $title)=$xoopsDB->fetchRow($result)){
$main.="<option value='$gsn'>{$title}</option>";
}
return $main;
}
//取得該分類下的通訊錄資料
function get_contact($gsn){
global $xoopsDB ;
$sql = "select * from `".$xoopsDB->prefix("contact")."` where gsn='$gsn'";
$result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'],3, mysql_error());
$all_content="";
while($all=$xoopsDB->fetchArray($result)){
//以下會產生這些變數: $tel , $email , $name , $gsn , $sn , $birthday , $zip , $county , $city , $addr
foreach($all as $k=>$v){
$$k=$v;
}
$cate=get_contact_cate_all();
$all_content.="
<tr>
<td>{$cate[$gsn]['title']}</td>
<td><a href='index.php?sn=$sn'>{$name}</a></td>
<td>{$tel}</td>
<td>{$email}</td>
<td>{$birthday}</td>
<td>{$zip} {$county}{$city}{$addr}</td>
</tr>
";
}
return $all_content;
}
?>