第36例:
使用分支语句加载不同网页主体
$shop_id=$_GET['id'];
switch($shop_id)
{
case "shop1"://如果ID为shop1
require("shop1.php");
break;
case "shop2":
require("shop2.php");
break;
case "shop3":
require("shop3.php");
break;
default://默认的选择
require("shop1.php");
}
?>
第37例:
php万年历
header("Content-type:text/html;charset=utf-8");
date_default_timezone_set("Asia/Shanghai");//设置日期时区为中国时区
$today = time();
$year =@$_GET["year"];
$month = @$_GET["month"];
if($year=='') $year = date("Y",$today);
if($month=='') $month = date("m",$today);
if((int)$month==0){$year-=1;$month=12;}
$time = mktime(0,0,0,$month,1,$year);//格式化当前日期
$year = date('Y',$time);
$month = date('m',$time);
$days = date('t',$time);//当前月份一共有几天
$fstdw = date('N',$time);//当前月份第一天为星期几
echo "";
echo ""; $str = ""; $str .= " ".$year."年 "; $str .= ""; $str .= " "; $str .= ""; $str .= " ".$month."月 "; $str .= ""; $str .= " "; echo $str; echo " |
";
echo"";
$str = "一 | ";
$str .= "二 | ";
$str .= "三 | ";
$str .= "四 | ";
$str .= "五 | ";
$str .= "六 | ";
$str .= "七 | ";
echo $str;
echo "";
$rows = ceil(($days + $fstdw-1)/7);
$cd = 1;
for($i=0;$i<$rows;$i++){
echo "";
for($j=0;$j<7;$j++){
echo ""; if($cd >= $fstdw && $cd<$days+$fstdw){ $oday = $cd-$fstdw+1; if($oday == date('d',time())){ echo ""; } echo $oday; }else{ echo "."; } $cd++; echo " | ";
}
echo "
";
}
echo "
";
?>
第38例:
index.php页面:
header("Content-Type:text/html;charset=utf-8");
mysql_connect("localhost","root","123456") or die("数据库连接有误!");
mysql_select_db("student") or die("数据库选择有误!");
mysql_query("set names 'utf8'");
?>
用户管理
body{text-align:center;}
#header{width:600px;height:50px;margin:10px;background:#E3EFFB;line-height:50px;font-size:20px;}
#main{width:600px;margin:10px;margin:0px auto;}
#main table{widt h:600px;background:#E3EFFB;cellspacing:1px;text-align:center;}
#main table tr{background:white;}
#main table img{border:0px;}
#page{width:600px;height:30px;background:#E3EFFB;line-height:30px;}
check.php页面:
PRINT("");
print_r($_POST);
exit();
header("Content-Type:text/html;charset=utf-8");
mysql_connect("localhost","root","123456") or die("数据库连接有误!");
mysql_select_db("student") or die("数据库选择有误!");
mysql_query("set names 'utf8'");
if(!empty($_POST['member_id'])){
$arr=$_POST['member_id'];
$str_key="";
foreach($arr as $key=>$value){
$sql="delete from student where member_id =".$value;
mysql_query($sql);
$str_key.=$value.",";
}
$new_str=substr($str_key,0,strlen($str_key)-1);
echo"";
}
?>