各位大虾 小弟我刚学php不久 有个smarty数组提取值问题.[size=13px]我的问题是:smarty是如何遍历数据库里不同字段的?[/size]这是我的数据库表 users
----+----------------+----------+-------------------------+-------+
ID | NAME | PASSWORD | EMAIL | MAJOR |
----+----------------+----------+-------------------------+-------+
2 | suboay | 1234 | [email protected] | 5 |
23 | suboyang | suboyang | [email protected] | 14 |
4 | zhohshuying | 123123 | [email protected] | 3 |
5 | qweqwe | qwewqe | [email protected] | 7 |
6 | 123213suboyang | 12323 | [email protected] | 3 |
----+----------------+----------+-------------------------+-------+这是我php文件,这里会有问题,但我也迷茫在这里
include('smarty_Inc.php');
include('conn.php');
$sql="select * from users";
$result=mysql_query($sql);
while($row=mysql_fetch_array($result))
{
$mylist[]=$row['NAME'];
$mylist[]=$row['PASSWORD'];} $smarty->assign("test",$mylist);
$smarty->display("forum_list.html"); // 该文件就是模板文件,应该在模板目录下}这是我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>
请问各位高手你们是怎么做的,能同时遍历出一张表里name和password?
----+----------------+----------+-------------------------+-------+
ID | NAME | PASSWORD | EMAIL | MAJOR |
----+----------------+----------+-------------------------+-------+
2 | suboay | 1234 | [email protected] | 5 |
23 | suboyang | suboyang | [email protected] | 14 |
4 | zhohshuying | 123123 | [email protected] | 3 |
5 | qweqwe | qwewqe | [email protected] | 7 |
6 | 123213suboyang | 12323 | [email protected] | 3 |
----+----------------+----------+-------------------------+-------+这是我php文件,这里会有问题,但我也迷茫在这里
include('smarty_Inc.php');
include('conn.php');
$sql="select * from users";
$result=mysql_query($sql);
while($row=mysql_fetch_array($result))
{
$mylist[]=$row['NAME'];
$mylist[]=$row['PASSWORD'];} $smarty->assign("test",$mylist);
$smarty->display("forum_list.html"); // 该文件就是模板文件,应该在模板目录下}这是我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>
请问各位高手你们是怎么做的,能同时遍历出一张表里name和password?
{$list.name}
{/foreach}
while($row=mysql_fetch_array($result))
{
$mylist[]=$row;//这样}
while($row=mysql_fetch_array($result))
{
$mylist["name"][]=$row['NAME'];
$mylist["password"][]=$row['PASSWORD'];}