smarty模板中如何停止单页循环?只是数组分页循环?求高手指路! 50
我知道问题出在$i这个函数上,应该怎么写?刚刚接触php,如果10行为1页怎么写,求高手指路!index.php代码<?phpinclude_once("libs/Sma...
我知道问题出在$i这个函数上,应该怎么写?刚刚接触php,如果10行为1页怎么写,求高手指路!
index.php代码
<?php
include_once("libs/Smarty.class.php");
include('condb.php');
header("Content-type: text/html; charset=utf-8");
$smarty=new Smarty();
$smarty->template_dir="templates";
$smarty->compile_dir="templates_c";
$smarty->left_delimiter="<{";
$smarty->right_delimiter="}>";
$smarty->config_dir="demo/config";
//$smarty->caching=true;//开启缓存
//$smarty->cache_dir="../demo/cache";//缓存文件存放的路径
if(!$connection){
die("could not connect to the database:</br>".mysql_error());//诊断连接错误
}
$db_selecct=mysql_select_db($db_database);//选择数据库
if(!$db_selecct)
{
die("could not to the database</br>".mysql_error());
}
$query="select name,password from member";//构建查询语句
$result=mysql_query($query);//执行查询
if(!$result)
{
die("could not to the database</br>".mysql_error());
}
$i=0;
while ($row=mysql_fetch_array($result))
{
$i++;
$num=$row[0];
$age=$row[1];
$smarty->assign("username", $num); //进行模板变量替换
$smarty->assign("password", $age);
$smarty->display("5.tpl");
}
?>
5.tpl模板代码
<{include file="header.tpl"}>
<body>
<h4>图片</h4><{$username}>
<{$password}>
</body>
<{include file="footer.tpl"}>
输出是
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<h4>图片</h4>12333
12345
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<h4>图片</h4>23336
68999
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<h4>图片</h4>23333
12333
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<h4>图片</h4>11231
23333
</body>
</html> 展开
index.php代码
<?php
include_once("libs/Smarty.class.php");
include('condb.php');
header("Content-type: text/html; charset=utf-8");
$smarty=new Smarty();
$smarty->template_dir="templates";
$smarty->compile_dir="templates_c";
$smarty->left_delimiter="<{";
$smarty->right_delimiter="}>";
$smarty->config_dir="demo/config";
//$smarty->caching=true;//开启缓存
//$smarty->cache_dir="../demo/cache";//缓存文件存放的路径
if(!$connection){
die("could not connect to the database:</br>".mysql_error());//诊断连接错误
}
$db_selecct=mysql_select_db($db_database);//选择数据库
if(!$db_selecct)
{
die("could not to the database</br>".mysql_error());
}
$query="select name,password from member";//构建查询语句
$result=mysql_query($query);//执行查询
if(!$result)
{
die("could not to the database</br>".mysql_error());
}
$i=0;
while ($row=mysql_fetch_array($result))
{
$i++;
$num=$row[0];
$age=$row[1];
$smarty->assign("username", $num); //进行模板变量替换
$smarty->assign("password", $age);
$smarty->display("5.tpl");
}
?>
5.tpl模板代码
<{include file="header.tpl"}>
<body>
<h4>图片</h4><{$username}>
<{$password}>
</body>
<{include file="footer.tpl"}>
输出是
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<h4>图片</h4>12333
12345
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<h4>图片</h4>23336
68999
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<h4>图片</h4>23333
12333
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<h4>图片</h4>11231
23333
</body>
</html> 展开
展开全部
$productBasicInfo 是 $value
productName 是数组键名..
不是数组是什么??
foreach( $productInfo as $key=>$value)
{ echo $value['productName']; }
---------------------
{foreach from=$(你传过来的数组) item=arr}
{foreach from=$arr item=arr1 key=k}
{if k eq (键值)}
{arr1}
{/if}
{/foreach}
{/foreach}
productName 是数组键名..
不是数组是什么??
foreach( $productInfo as $key=>$value)
{ echo $value['productName']; }
---------------------
{foreach from=$(你传过来的数组) item=arr}
{foreach from=$arr item=arr1 key=k}
{if k eq (键值)}
{arr1}
{/if}
{/foreach}
{/foreach}
追问
????啥东西?哪里复制的?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询