線上書籍

Home

[1062] PHP7入門

<?php require_once 'function.php'; require_once 'smarty/libs/Smarty.class.php'; $smarty = new Smarty; $db = link_db(); $op = isset($_REQUEST['op']) ? filter_var($_REQUEST['op']) : ''; switch ($op) { default: list_article(); break; } $smarty->display('index.tpl'); //讀出所有文章 function list_article() { global $db, $smarty; $sql = "SELECT * FROM `article` ORDER BY `update_time` DESC"; $result = $db->query($sql) or die($db->error); $all = []; while ($data = $result->fetch_assoc()) { $all[] = $data; } // die(var_export($all)); $smarty->assign('all', $all); }