PHP类的include以及赋值路径,以及显示模板
2013-02-12 22:59
155 查看
<?php // smarty.php $path = $_SERVER['DOCUMENT_ROOT']; require "$path/Smarty/Smarty.class.php"; $smarty = new Smarty(); $smarty->template_dir = "$path/temp/smarty/templates"; $smarty->compile_dir = "$path/temp/smarty/templates_c"; $smarty->cache_dir = "$path/temp/smarty/cache"; $smarty->config_dir = "$path/temp/smarty/configs"; $smarty->assign('title', 'Test Web Page'); $smarty->display("index.tpl"); ?> // index.tpl <html> <head> <title>{$title}</title> </head> <body> This is a Smarty Test </body> </html> // ------------------------------------------------------------------ <?php // smartytest.php $path = $_SERVER['DOCUMENT_ROOT']; require "$path/Smarty/Smarty.class.php"; $smarty = new Smarty(); $smarty->template_dir = "$path/temp/smarty/templates"; $smarty->compile_dir = "$path/temp/smarty/templates_c"; $smarty->cache_dir = "$path/temp/smarty/cache"; $smarty->config_dir = "$path/temp/smarty/configs"; require_once("$path/temp/login.php"); $db_server = mysql_connect($db_hostname, $db_username, $db_password); if (!$db_server) die("Unable to connect to MySQL: " . mysql_error()); mysql_select_db($db_database) or die("Unable to select database: " . mysql_error()); if (isset($_POST['author']) && isset($_POST['title']) && isset($_POST['category']) && isset($_POST['year']) && isset($_POST['isbn'])) { $author = get_post('author'); $title = get_post('title'); $category = get_post('category'); $year = get_post('year'); $isbn = get_post('isbn'); if (isset($_POST['delete']) && $isbn != "") { $query = "DELETE FROM classics WHERE isbn='$isbn'"; if (!mysql_query($query)) { echo "DELETE failed: $query<br>" . mysql_error() . "<p>"; } } else { $query = "INSERT INTO classics VALUES" . "('$author', '$title', '$category', '$year', '$isbn')"; if (!mysql_query($query)) { echo "INSERT failed: $query<br>" . mysql_error() . "<p>"; } } } $query = "SELECT * FROM classics"; $result = mysql_query($query); if (!$result) die ("Database access failed: " . mysql_error()); $rows = mysql_num_rows($result); for ($j = 0 ; $j < $rows ; ++$j) { $results[] = mysql_fetch_array($result); } mysql_close($db_server); $smarty->assign('results', $results); $smarty->display("smartytest.tpl"); function get_post($var) { return mysql_real_escape_string($_POST[$var]); } ?> // ------------------------------------------------------ <html><head> <title>Smarty Test</title> </head><body> <form action="smartytest.php" method="post"><pre> Author <input type="text" name="author"> Title <input type="text" name="title"> Category <input type="text" name="category"> Year <input type="text" name="year"> ISBN <input type="text" name="isbn"> <input type="submit" value="ADD RECORD"> </pre></form> {section name=row loop=$results} <form action="smartytest.php" method="post"> <input type="hidden" name="delete" value="yes"> <input type="hidden" name="isbn" value="{$results[row].isbn}"> <pre> Author {$results[row].author} Title {$results[row].title} Category {$results[row].category} Year {$results[row].year} ISBN {$results[row].isbn} <input type="submit" value="DELETE RECORD"></pre> </form> {/section} </body></html>
相关文章推荐
- php获取文件夹路径内的图片以及分页显示示例
- springmvc 配置默认路径 以及 Jsp include跳转controller 以及 url get访问中文乱码
- php获取文件夹路径内的图片以及分页显示示例
- 跨线程为控件赋值并保持listview选中状态以及在可见区域显示
- easyUi 打开对话框后控件赋值,以及赋值后不显示的问题
- 推荐用于格式化以及高亮显示SQL文的PHP类-SqlFormatter
- Html中相对路径和绝对路径 以及相对路径下照片不显示的解决
- TP5 assign给模板变量赋值(或者取得参数值,在模板中显示出来)
- mysql 启动失败 和 php路径错误 以及 php 无法显示的问题
- 拍照并显示以及获取路径后上传
- onchange,onpropertychange,oninput键盘输入和js赋值时区别,以及输入密码时显示的是星号
- 简单的 Android 拍照并显示以及获取路径后上传
- netbeans如何去掉竖着的红线以及在左上角标题栏目显示完整文件路径
- gcc选项--显示include的路径
- 关于aspx模板页面元素路径的问题,以及对模板页面的理解
- Repeater进行模板设计以及实现数据的分页显示
- C和C++中include 搜索路径的一般形式以及gcc搜索头文件的路径
- C和C++中include 搜索路径的一般形式以及gcc搜索头文件的路径
- Jsp中图片显示问题以及显示绝对路径图片问题
- jsoup操作模板代码,给radio select input 赋值,以及select回显