php和smarty问题 本帖最后由 spg120 于 2011-01-09 21:50:55 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 $row[] = $db->fetch_row($query); $sql="SELECT * FROM `message` where id = ".$_GET[id];由于这句话就是根据id查处一行的值啊。 smarty模板的问题参考http://www.smarty.net/docsv2/en/language.function.section.tpl{section name=customer loop=$row} id: {$row[customer][1]}<br />{/section} 恩 赋值$row[]=mysql_fetch_array()or array_push($row,$row[id]); 数组$row assign以后到页面 按照 {$row.key}读取如 {$row.id}{$row.user}{$row.title} 首先 mysql与smarty没有关系只要把结果集转化为正常的数组 然后按照上面的写法就可以了 不好使啊 难道你们是这么写的 $sql="select * from users";//表里有password 和name $result=mysql_query($sql);$row=mysql_fetch_array($result) $smarty->assign("test",$row); $smarty->display("index.htm"); }这是我html文件,如果这样写只能遍出历 头一个字母<table> {section name=list loop=$test} <tr> <td> {$test[list].name} </td>//这里我想遍历出NAME <td> </td> <td> {$test[list].password} </td>//这里我想遍历出PASSWORD <td height="44">5</td> </tr> {/section} </table> $row=$db->fetch_row($query);这个查询出来的是一维数组,所以你在index.htm 页面这样就行了标题:{$row.title} 内容:{$row.content}如果你查询出来的是二维数组 (比如列表页)你就这样了 {foreach from=$newslist item=r} <tr> <td><a href="index.php?m=show&id={$r.id}">{$r.title}</a></td> </tr>{/foreach}section和foreach 都是循环的,foreach 比较简单直观,没有section功能多 参考http://topic.csdn.net/u/20110110/12/3d399672-271f-42c7-94cb-fa4cd0a3dced.html {foreach from=$array key=$key,;item=$value}echo $key:$value {foreach item=value key=key from=$StieInfo}{$key} : {$value}{/foreach} 一年没来,循例散分 下拉菜单,不是导航那种 php如何得到access数据库返回的行数。急!急 AJAX投递后没返回信息? 怎样才能让页面重自动刷新时,把PHP也再执行? php怎么循环数组 关于url中存在%后apache报Bad Request的问题 php中的md5和asp中写成的md5算法为什么不同?巨急? 获取html标签的函数. 在局域网或单机上中如何......? php include 路径问题 拟目录收录快还是单一入口收录快呢?
由于这句话就是根据id查处一行的值啊。
参考
http://www.smarty.net/docsv2/en/language.function.section.tpl
{section name=customer loop=$row}
id: {$row[customer][1]}<br />
{/section}
or array_push($row,$row[id]);
{$row.user}
{$row.title}
只要把结果集转化为正常的数组 然后按照上面的写法就可以了
难道你们是这么写的
$sql="select * from users";//表里有password 和name
$result=mysql_query($sql);
$row=mysql_fetch_array($result)
$smarty->assign("test",$row);
$smarty->display("index.htm");
}这是我html文件,如果这样写只能遍出历 头一个字母
<table>
{section name=list loop=$test}
<tr>
<td> {$test[list].name} </td>//这里我想遍历出NAME
<td> </td>
<td> {$test[list].password} </td>//这里我想遍历出PASSWORD
<td height="44">5</td>
</tr>
{/section}
</table>
这个查询出来的是一维数组,所以你在index.htm 页面这样就行了
标题:{$row.title}
内容:{$row.content}
如果你查询出来的是二维数组 (比如列表页)
你就这样了 {foreach from=$newslist item=r}
<tr>
<td><a href="index.php?m=show&id={$r.id}">{$r.title}</a></td>
</tr>
{/foreach}section和foreach 都是循环的,foreach 比较简单直观,没有section功能多
http://topic.csdn.net/u/20110110/12/3d399672-271f-42c7-94cb-fa4cd0a3dced.html
echo $key:$value
{$key} : {$value}
{/foreach}