PHP Smarty增刪改查

來源:互聯網
上載者:User

標籤:

設定檔 init.inc.php

<?phpdefine("ROOT",str_replace("\\","/",dirname(__FILE__)).‘/‘); //常量ROOT中指定項目根目錄(常量的名稱,常量的值)//當前檔案的目錄,不包含檔案名稱 dirname(__FILE__))require ROOT.‘libs/Smarty.class.php‘; //載入Smarty類檔案$smarty = new Smarty(); //執行個體化Smarty對象<br>//設定初始路徑//$smarty -> auto_literal = false; //就可以讓定界符號使用空格$smarty->setTemplateDir(ROOT.‘templates/‘); //設定所有模板檔案存放位置//$smarty->addTemplateDir(ROOT.‘templates2/‘); //添加一個模板檔案夾$smarty->setCompileDir(ROOT.‘templates_c/‘); //設定編譯過的模板存放的目錄$smarty->addPluginsDir(ROOT.‘plugins/‘); //設定為模板擴充外掛程式存放目錄$smarty->setCacheDir(ROOT.‘cache/‘); //設定快取檔案存放目錄$smarty->setConfigDir(ROOT.‘configs/‘); //設定模板設定檔存放目錄$smarty->caching = false; //設定Smarty緩衝開關功能$smarty->cache_lifetime = 60*60*24; //設定緩衝模板有效時間一天$smarty->left_delimiter = ‘<{‘; //設定範本語言中的左結束符$smarty->right_delimiter = ‘}>‘; //設定範本語言中的右結束符?>

main.php

<?phpinclude("../init.inc.php");include("../../dbda.php");$db=new DBDA();$stimu="select * from timu";$timu=$db->Query($stimu);foreach($timu as $k=>$v){    //處理正確答案名稱    $sxuanxiang="select name from xuanxiang where timu={$v[0]} and xuanxiang=‘{$v[2]}‘";    $timu[$k][2]=$db->StrQuery($sxuanxiang);                    //處理科目名稱    $skemu="select name from kemu where code=‘{$v[3]}‘";    $timu[$k][3]=$db->StrQuery($skemu);        //處理難度名稱    $snandu="select name from nandu where code=‘{$v[4]}‘";    $timu[$k][4]=$db->StrQuery($snandu);        //處理類型名稱    $sleixing="select name from leixing where code=‘{$v[5]}‘";    $timu[$k][5]=$db->StrQuery($sleixing);}$smarty->assign("timu",$timu);$smarty->display("main.html");

main.html

<style type="text/css">.a{    padding-left:150px;    padding-top:50px;}.but{    padding-left:1100px;}</style></head><body><div class="a">    <table width="1000px" border="1" cellpadding="0" cellspacing="0">        <tr height="30px" align="center" style="font-weight:bold" >            <td>題目名稱</td>            <td>答案</td>            <td>科目</td>            <td>難度</td>            <td>類型</td>            <td>操作</td>        </tr>        <{foreach $timu as $v}>        <tr height="25px" align="center" >             <td><{$v[1]|truncate:5}></td>            <td><{$v[2]}></td>            <td><{$v[3]}></td>            <td><{$v[4]}></td>            <td><{$v[5]}></td>                         <td><a href="update.php?code=<{$v[0]}>">修改</a>&nbsp;&nbsp;<a href="delete.php?code=<{$v[0]}>">刪除</a>&nbsp;&nbsp;<a href="">查看詳情</a></td>        </tr>        <{/foreach}>    </table></div><br /><div class="but"><a href="add.php">添加資料</a></div>

                                       

update.php

<?phpinclude("../init.inc.php");include("../../dbda.php");$db=new DBDA();$code=$_GET["code"];$stimu="select * from timu where code=‘{$code}‘";$timu=$db->Query($stimu);$sxuanxiang="select * from xuanxiang where timu=‘{$code}‘  order by code asc";$xuanxiang=$db->Query($sxuanxiang);$skemu="select * from kemu";$kemu=$db->Query($skemu);$snandu="select * from nandu";$nandu=$db->Query($snandu);$sleixing="select * from leixing";$leixing=$db->Query($sleixing);$smarty->assign("kemu",$kemu);$smarty->assign("timu",$timu);$smarty->assign("nandu",$nandu);$smarty->assign("leixing",$leixing);$smarty->assign("xuanxiang",$xuanxiang);$smarty->display("update.html");

updatechuli.php

<?php$code=$_GET["code"];include("../../dbda.php");$db=new DBDA();$sxuanxiang="delete from xuanxiang where timu=‘{$code}‘";$xuanxiang=$db->Query($sxuanxiang,0);$stimu="delete from timu where code=‘{$code}‘";$timu=$db->Query($stimu,0);$name=$_POST["name"];$daan=$_POST["daan"];$kemu=$_POST["kemu"];$nandu=$_POST["nandu"];$type=$_POST["type"];$a=$_POST["a"];$b=$_POST["b"];$c=$_POST["c"];$d=$_POST["d"];//添加題目$stimu="insert into timu values(‘‘,‘{$name}‘,‘{$daan}‘,‘{$kemu}‘,‘{$nandu}‘,‘{$type}‘)";$timu=$db->Query($stimu,0);if($timu){    //取上面添加的題目的代號    $id=$db->conn->insert_id;            //添加選項    $sxxa="insert into xuanxiang values(‘‘,‘{$a}‘,‘A‘,‘{$id}‘)";    $db->Query($sxxa,0);    $sxxb="insert into xuanxiang values(‘‘,‘{$b}‘,‘B‘,‘{$id}‘)";    $db->Query($sxxb,0);    $sxxc="insert into xuanxiang values(‘‘,‘{$c}‘,‘C‘,‘{$id}‘)";    $db->Query($sxxc,0);    $sxxd="insert into xuanxiang values(‘‘,‘{$c}‘,‘D‘,‘{$id}‘)";    $db->Query($sxxd,0);            header("location:add.php");}else{    echo"添加失敗";}

 

PHP Smarty增刪改查

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.