第36例:
使用分支语句加载不同网页主体
<div id="header">
<!--页面导航条-->
<ul>
<li><a href="?id=shop1">基本商品</a></li>
<li><a href="?id=shop2">推荐商品</a></li>
<li><a href="?id=shop3">分类商品</a></li>
</ul>
</div>
<div id="content">
<!--此处动态更改主体内容-->
</div>
<?php
$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万年历
<?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 "<table border=1 width=260 cellspacing=0 cellpadding=0 align=center bgcolor=#cccccc>";
echo "<tr><td colspan=7 class=title>";
$str = "<a href=?year=".($year-1)."&month=".$month.">";
$str .= "</a> ".$year."年 ";
$str .= "<a href=?year=".($year+1)."&month=".$month.">";
$str .= "</a> ";
$str .= "<a href=?year=".$year."&month=".($month-1).">";
$str .= "</a> ".$month."月 ";
$str .= "<a href=?year=".$year."&month=".($month+1).">";
$str .= " </a>";
echo $str;
echo "</td></tr>";
echo"<tr>";
$str = "<td>一</td>";
$str .= "<td>二</td>";
$str .= "<td>三</td>";
$str .= "<td>四</td>";
$str .= "<td>五</td>";
$str .= "<td>六</td>";
$str .= "<td>七</td>";
echo $str;
echo "</td>";
$rows = ceil(($days + $fstdw-1)/7);
$cd = 1;
for($i=0;$i<$rows;$i++){
echo "<tr>";
for($j=0;$j<7;$j++){
echo "<td>";
if($cd >= $fstdw && $cd<$days+$fstdw){
$oday = $cd-$fstdw+1;
if($oday == date('d',time())){
echo "<font color='red'><b><u>";
}
echo $oday;
}else{
echo ".";
}
$cd++;
echo "</td>";
}
echo "</tr>";
}
echo "</table>";
?>
第38例:
index.php页面:
<?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'");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>用户管理</title>
<style>
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;}
</style>
</head>
<body>
<div id="header">网站管理中心--会员列表</div>
<div id="main">
<form name="myForm" action="check.php" method="post">
<table>
<tr>
<th width="100">编号</th>
<th width="150">用户名</th>
<th width="200">邮件地址</th>
<th width="200">注册日期</th>
<th width="50">选择</th>
</tr>
<?php
//定义分页所需要的变量
$page=isset($_GET['page'])?$_GET['page']:1;//当前页
$pagesize=5; //每页显示的条数
//获取总条数数据
$sql="select count(*) from student";
$result=mysql_query($sql);
$maxrows=mysql_result($result,0,0);
$maxpage=ceil($maxrows/$pagesize);
//到达最后一页判断
if($page>$maxpage){
$page=$maxpage;
}
//到达第一页判断
if($page<1){
$page=1;
}
$offset=($page-1)*$pagesize;
$sql="select * from student limit {$offset},$pagesize";
$result=mysql_query($sql);
while($rows=mysql_fetch_assoc($result)){
echo "<tr>";
echo "<td>{$rows['member_id']}</td>";
echo "<td>{$rows['username']}</td>";
echo "<td>{$rows['email']}</td>";
echo "<td>".date("Y-m-d H:i:s",$rows['registertime']+8*3600)."</td>";
echo "<td><input type='checkbox' value='{$rows['member_id']}' name='member_id[]'></td>";
echo "</tr>";
}
?>
</table>
<br/>
<div id="page">
<?php
echo "当前{$page}/{$maxpage}页 共计{$maxrows}条信息 ";
echo "<a href='user.php?page=1'>首页</a> ";
echo "<a href='user.php?page=".($page-1)."'>上一页</a> ";
echo "<a href='user.php?page=".($page+1)."'>下一页</a> ";
echo "<a href='user.php?page=".$maxpage."'>最后一页</a>";
echo " <input type='submit' value='批量删除'>";
?>
</div>
</form>
</div>
</body>
<html>
check.php页面:
<?php
PRINT("<PRE>");
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"<script>alert('删除编号为".$new_str."的信息成功!');location='user.php'</script>";
}
?>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。