<?php
//引用类文件
$mysql_server_name="localhost"; //数据库服务器名称
$mysql_username="root"; // 连接数据库用户名
$mysql_password=""; // 连接数据库密码
$mysql_database="test"; // 数据库的名字
$conn=mysql_connect($mysql_server_name, $mysql_username,$mysql_password);
$query=mysql_query("select * from text");
require 'smarty/libs/Smarty.class.php';
$smarty = new Smarty;
//设置各个目录的路径,这里是安装的重点
$smarty->template_dir = "smarty/templates/templates";
$smarty->compile_dir = "smarty/templates/templates_c";
$smarty->config_dir = "smarty/templates/config";
$smarty->cache_dir = "smarty/templates/cache";
while($arr=$query){
$list=array("id"=>$arr->id,username=>$arr->username,password=>$arr->password);
}
print_r($list);
$smarty->assign("user",$list);
$smarty->display("index.tpl"); echo $list;?>
{section name=loop loop=$user}用户名:{$user[loop].username}<br>
密码:{$user[loop].password}
{/section}
为什么显示不出任何东西,不懂!在线等待高手
我不知道你那么写对不对,不过这种写法绝对是最标准的。
while($arr=$query){
$list=array("id"=>$arr->id,username=>$arr->username,password=>$arr->password);
}
这里也有问题,
while($arr=mysql_fetch($query))才可以,不然肯定是没有东西的,因为数据压根就没取出来~~
$conn=mysql_connect($mysql_server_name, $mysql_username,$mysql_password);
这行后面加一句:
mysql_select_db($mysql_database);
这行后面加一句:
mysql_select_db($mysql_database);之后就报错了 Fatal error: Maximum execution time of 30 seconds exceeded in D:\wamp\www\test\index.php on line 16
最前面加一句set_time_limit(0);
//引用类文件
$mysql_server_name="localhost"; //数据库服务器名称
$mysql_username="root"; // 连接数据库用户名
$mysql_password=""; // 连接数据库密码
$mysql_database="test"; // 数据库的名字
$conn=mysql_connect($mysql_server_name, $mysql_username,$mysql_password);
mysql_select_db("dbname");
$query=mysql_query("select * from text");
require 'smarty/libs/Smarty.class.php';
$smarty = new Smarty;
//设置各个目录的路径,这里是安装的重点
$smarty->template_dir = "smarty/templates/templates";
$smarty->compile_dir = "smarty/templates/templates_c";
$smarty->config_dir = "smarty/templates/config";
$smarty->cache_dir = "smarty/templates/cache";
while($arr=mysql_fetch_array($query)){
$list[]=array("id"=>$arr->id,username=>$arr->username,password=>$arr->password);
}
print_r($list);
$smarty->assign("user",$list);
$smarty->display("index.tpl"); echo $list;?>