11-15诸多代码子~

stu_info.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"}>




学生基本信息


 


 

学生基本信息


 
     
 

  <{section name='stu' loop=$array}>
    <{if $smarty.section.stu.index is odd}>

   
   
   
 
    

<{else}>
   
   
   
   
 
    

<{/if}>
  <{/section}>
 
 
学号姓名生日成绩详细信息
<{$array[stu].id}><{$array[stu].name}><{$array[stu].birthday}><{$array[stu].score}>详细信息
<{$array[stu].id}><{$array[stu].name}><{$array[stu].birthday}><{$array[stu].score}>详细信息

 



details.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"}>




学生详细信息



<{section name=stu_detail loop=$stu_details}>
   

<{$stu_details[stu_detail].name}>的详细信息



    学号:<{$stu_details[stu_detail].id}>

姓名:<{$stu_details[stu_detail].name}>

生日:<{$stu_details[stu_detail].birthday}>

成绩:<{$stu_details[stu_detail].score}>

<{/section}>



查看下一个



connect.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诸多代码子~)