線上書籍

Home

[1012]PHP進階開發及TadTools工具應用

<?php /*-----------引入檔案區--------------*/ include_once "header.php"; $xoopsOption['template_main'] = "contact_index_tpl.html"; /*-----------function區--------------*/ //列出所有contact資料 function list_contact(){ global $xoopsDB , $xoopsModule , $isAdmin; $sql = "select * from `".$xoopsDB->prefix("contact")."` "; $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> "; } $jquery=get_jquery(); //刪除確認的JS $main=" $jquery <script type='text/javascript'> $(document).ready(function(){ $.post('ajax.php' , function(data){ $('#menu1').html(data); $.post('ajax.php' , {parent_gsn: $('#menu1').val()} , function(data){ $('#menu2').html(data); }); }); $('#menu1').change(function(){ $.post('ajax.php' , {parent_gsn: $('#menu1').val()} , function(data){ $('#menu2').html(data); }); }); }); </script> <select id='menu1'></select> <select name='gsn' id='menu2'></select> <table summary='list_table' id='tbl' style='width:100%;'> <tr> <th>群組</th> <th>姓名</th> <th>電話</th> <th>信箱</th> <th>生日</th> <th>地址</th> </tr> <tbody> $all_content </tbody> <tr> <td colspan=11 class='bar'> </td> </tr> </table>"; //raised,corners,inset $main=div_3d("",$main,"corners"); return $main; } //以流水號秀出某筆contact資料內容 function show_one_contact($sn=""){ global $xoopsDB , $xoopsModule , $isAdmin; if(empty($sn)){ return; }else{ $sn=intval($sn); } $sql = "select * from `".$xoopsDB->prefix("contact")."` where `sn` = '{$sn}' "; $result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'],3, mysql_error()); $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($gsn); $data=" <table summary='list_table' id='tbl' style='width:100%;'> <tr><th nowrap>電話</th><td>{$tel}</td></tr> <tr><th nowrap>信箱</th><td>{$email}</td></tr> <tr><th nowrap>生日</th><td>{$birthday}</td></tr> <tr><th nowrap>地址</th><td>{$zip} {$county}{$city}{$addr}</td></tr> </table>"; //raised,corners,inset $main=div_3d("{$cate['title']} / {$name}",$data,"corners"); return $main; } /*-----------執行動作判斷區----------*/ $op=empty($_REQUEST['op'])?"":$_REQUEST['op']; $sn=empty($_REQUEST['sn'])?"":intval($_REQUEST['sn']); $gsn=empty($_REQUEST['gsn'])?"":intval($_REQUEST['gsn']); $files_sn=empty($_REQUEST['files_sn'])?"":intval($_REQUEST['files_sn']); switch($op){ default: if(empty($sn)){ $main=list_contact(); }else{ $main=show_one_contact($sn); } break; } /*-----------秀出結果區--------------*/ module_footer($main); ?>