自己寫了一個把文章標題從數據庫中讀出,並且賦值給一個數組,最後通過smarty循環顯示出來

php程序:

<?php
require_once("conn_inc.php");
require_once("smarty_inc.php");
$arr=array();
$query=mysql_query("select * from new order by id desc");
while ($row=mysql_fetch_array($query)){
array_push(&$arr,$row[title]); 
}
$smarty->assign("arr",$arr);
$smarty->display("new_list_html.tpl.html");
?>

smarty程序:

<html>
<head>
<title>文章列表</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<table border="1">
<tr>
<td>ID</td>
</tr>
{foreach from=$arr item=title key=j}
<tr>
<td>{$j}--{$title}</td>
</tr>
{/foreach}
</table>
</body>
</html>

發佈了29 篇原創文章 · 獲贊 0 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章