11-15诸多代码子~

stu_info.php

<?php
include('connect.php');
include('libs/Smarty.class.php');
$smarty = new Smarty;
$smarty->reInitSmarty();
$smarty->caching=1;
if(!$smarty->is_cached('stu_info.tpl')){
$q = 'select *from stu';
$result = mysql_query($q);
$array = Array();
$i=0;
while($row = mysql_fetch_assoc($result)){
 $array[$i]=$row;
 $i++;
}
$smarty->assign('array',$array);
echo "当前模板文件没有被缓存";
}
$smarty->display('stu_info.tpl');
?>

stu_info.tpl

<{config_load file="test.conf"}>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>学生基本信息</title>
</head>
<body>
 <center>
  <h3>学生基本信息</h3>
  <table bgcolor='<{#table_bgcolor#}>' border='1'>
     <tr bgcolor='<{#head_color#}>'>
  <th>学号</th><th>姓名</th><th>生日</th><th>成绩</th><th>详细信息</th>
</tr>
  <{section name='stu' loop=$array}>
    <{if $smarty.section.stu.index is odd}>
<tr bgcolor='<{#row_color1#}>'>
  <td><{$array[stu].id}></td> 
  <td><{$array[stu].name}></td> 
  <td><{$array[stu].birthday}></td> 
  <td><{$array[stu].score}></td>
  <td><a href='details.php?id=<{$array[stu].id}>'>详细信息</a> </td>   
</tr>
<{else}>
   <tr bgcolor='<{#row_color2#}>'>
  <td><{$array[stu].id}></td> 
  <td><{$array[stu].name}></td> 
  <td><{$array[stu].birthday}></td> 
  <td><{$array[stu].score}></td>
  <td><a href='details.php?id=<{$array[stu].id}>'>详细信息</a> </td>   
</tr>
<{/if}>
  <{/section}>
 
  </table>
 </center>
</body>
</html>

details.php

<?php
  include('connect.php');
  include('libs/Smarty.class.php');
  $smarty = new Smarty;
  $smarty->reInitSmarty();
  $smarty->caching=1;
  if(!$smarty->is_cached('stu_details.tpl',$_GET['id'])){
 $q = "select * from stu where id = ".$_GET["id"];
 $result =mysql_query($q);
 $array = Array();
 $i=0;
 while($row= mysql_fetch_assoc($result)){
$array[$i]=$row;
$i++;
 }
 $smarty->assign('stu_details',$array);
 echo "缓存没有被设置哦~";
  }
  $smarty->display('stu_details.tpl',$_GET['id']);
?>

stu_details.tpl

<{config_load file="test.conf"}>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>学生详细信息</title>
</head>
<body>
<center>
<{section name=stu_detail loop=$stu_details}>
    <h1><{$stu_details[stu_detail].name}>的详细信息</h1><hr/>
    学号:<{$stu_details[stu_detail].id}><br/>
姓名:<{$stu_details[stu_detail].name}><br/>
生日:<{$stu_details[stu_detail].birthday}><br/>
成绩:<{$stu_details[stu_detail].score}><br/>
<{/section}>
<hr/>
<input type="button" value="上一页" onclick="history.back()">
<a href="details.php?id='$_GET['id']+1'">查看下一个</a>
</center>
</body>
</html>

connect.php


<?php
$link = mysql_connect('localhost','root','') or die("数据库连接失败!");
mysql_select_db('xsxx',$link);
mysql_query("set names utf8");
?>


test.conf


table_bgcolor = blue
head_color = yellow
row_color1 = red
row_color2 = green

你可能感兴趣的:(11-15诸多代码子~)