:::

5-3 上課範例:ajax.php

<?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;
}
?>

:::

搜尋

QR Code 區塊

https%3A%2F%2Ftad0616.net%2Fmodules%2Ftad_book3%2Fpage.php%3Ftbdsn%3D761%26tbsn%3D26

書籍目錄

展開 | 闔起

線上使用者

84人線上 (24人在瀏覽線上書籍)

會員: 0

訪客: 84

更多…