:::

3-2 上課範例:index.php

001<?php
002 
003/*-----------引入檔案區--------------*/
004include_once "header.php";
005$xoopsOption['template_main'] = "contact_index_tpl.html";
006/*-----------function區--------------*/
007 
008 
009//列出所有contact資料
010function list_contact(){
011    global $xoopsDB , $xoopsModule , $isAdmin;
012 
013    $sql = "select * from `".$xoopsDB->prefix("contact")."` ";
014    $result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'],3, mysql_error());
015 
016    $all_content="";
017 
018    while($all=$xoopsDB->fetchArray($result)){
019        //以下會產生這些變數: $tel , $email , $name , $gsn , $sn , $birthday , $zip , $county , $city , $addr
020        foreach($all as $k=>$v){
021            $$k=$v;
022        }
023 
024 
025        $cate=get_contact_cate_all();
026 
027        $all_content.="
028        <tr>
029            <td>{$cate[$gsn]['title']}</td>
030            <td><a href='index.php?sn=$sn'>{$name}</a></td>
031            <td>{$tel}</td>
032            <td>{$email}</td>
033            <td>{$birthday}</td>
034            <td>{$zip} {$county}{$city}{$addr}</td>
035        </tr>
036        ";
037    }
038     
039    $jquery=get_jquery();
040 
041    //刪除確認的JS
042    $main="
043    $jquery
044     
045    <script type='text/javascript'>
046  $(document).ready(function(){
047   
048    $.post('ajax.php' , function(data){
049      $('#menu1').html(data);
050      $.post('ajax.php' , {parent_gsn: $('#menu1').val()} , function(data){
051        $('#menu2').html(data);
052      });
053    });
054 
055 
056    $('#menu1').change(function(){
057      $.post('ajax.php' , {parent_gsn: $('#menu1').val()} , function(data){
058        $('#menu2').html(data);
059      });
060    });
061 
062 
063  });
064  </script>
065   
066    <select id='menu1'></select>
067    <select name='gsn' id='menu2'></select>
068     
069    <table summary='list_table' id='tbl' style='width:100%;'>
070    <tr>
071        <th>群組</th>
072        <th>姓名</th>
073        <th>電話</th>
074        <th>信箱</th>
075        <th>生日</th>
076        <th>地址</th>
077    </tr>
078 
079    <tbody>
080    $all_content
081    </tbody>
082 
083    <tr>
084        <td colspan=11 class='bar'>
085 
086        </td>
087    </tr>
088    </table>";
089 
090    //raised,corners,inset
091    $main=div_3d("",$main,"corners");
092 
093    return $main;
094}
095 
096//以流水號秀出某筆contact資料內容
097function show_one_contact($sn=""){
098    global $xoopsDB , $xoopsModule , $isAdmin;
099 
100    if(empty($sn)){
101        return;
102    }else{
103        $sn=intval($sn);
104    }
105 
106    $sql = "select * from `".$xoopsDB->prefix("contact")."` where `sn` = '{$sn}' ";
107    $result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'],3, mysql_error());
108    $all=$xoopsDB->fetchArray($result);
109 
110    //以下會產生這些變數: $tel , $email , $name , $gsn , $sn , $birthday , $zip , $county , $city , $addr
111    foreach($all as $k=>$v){
112        $$k=$v;
113    }
114 
115 
116    $cate=get_contact_cate($gsn);
117 
118    $data="
119    <table summary='list_table' id='tbl' style='width:100%;'>
120    <tr><th nowrap>電話</th><td>{$tel}</td></tr>
121    <tr><th nowrap>信箱</th><td>{$email}</td></tr>
122    <tr><th nowrap>生日</th><td>{$birthday}</td></tr>
123    <tr><th nowrap>地址</th><td>{$zip} {$county}{$city}{$addr}</td></tr>
124    </table>";
125 
126    //raised,corners,inset
127    $main=div_3d("{$cate['title']} / {$name}",$data,"corners");
128 
129    return $main;
130}
131/*-----------執行動作判斷區----------*/
132$op=empty($_REQUEST['op'])?"":$_REQUEST['op'];
133$sn=empty($_REQUEST['sn'])?"":intval($_REQUEST['sn']);
134$gsn=empty($_REQUEST['gsn'])?"":intval($_REQUEST['gsn']);
135$files_sn=empty($_REQUEST['files_sn'])?"":intval($_REQUEST['files_sn']);
136 
137 
138switch($op){
139 
140    default:
141  if(empty($sn)){
142    $main=list_contact();
143  }else{
144    $main=show_one_contact($sn);
145  }
146    break;
147}
148 
149/*-----------秀出結果區--------------*/
150module_footer($main);
151?>

:::

搜尋

QR Code 區塊

https%3A%2F%2Fmail.tad0616.cp22.secserverpros.com%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbdsn%3D751%26tbsn%3D26

書籍目錄

展開 | 闔起

線上使用者

40人線上 (6人在瀏覽線上書籍)

會員: 0

訪客: 40

更多…