您好,登錄后才能下訂單哦!
第36例:
使用分支語句加載不同網(wǎng)頁主體
<div id="header">
<!--頁面導(dǎo)航條-->
<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">
<!--此處動態(tài)更改主體內(nèi)容-->
</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");//設(shè)置日期時區(qū)為中國時區(qū)
$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);//格式化當(dāng)前日期
$year = date('Y',$time);
$month = date('m',$time);
$days = date('t',$time);//當(dāng)前月份一共有幾天
$fstdw = date('N',$time);//當(dāng)前月份第一天為星期幾
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("數(shù)據(jù)庫連接有誤!");
mysql_select_db("student") or die("數(shù)據(jù)庫選擇有誤!");
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">網(wǎng)站管理中心--會員列表</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;//當(dāng)前頁
$pagesize=5; //每頁顯示的條數(shù)
//獲取總條數(shù)數(shù)據(jù)
$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 "當(dāng)前{$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("數(shù)據(jù)庫連接有誤!");
mysql_select_db("student") or die("數(shù)據(jù)庫選擇有誤!");
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>";
}
?>
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。