[英]Display data from the database means php smarty mysql
帮助我了解:数据库中有一个表:
id f_gdpec w_gdpec url_gdpec p_gdspec
1 Москва Красноярск www.test.ru 450
2 Москва Красноярск www.test.ru 900
3 Москва Красноярск www.test.ru 600
需要从数据库中提取数据并显示意味着php意味着聪明。 那就是我所做的:module.php:
<?php
function mod_gdspec($module_id){
$inCore = cmsCore::getInstance();
$inDB = cmsDatabase::getInstance();
$cfg = $inCore->loadModuleConfig($module_id);
$sql = "SELECT f_gdpec,
w_gdpec,
url_gdpec,
p_gdspec
FROM cms_gdspec";
$result = $inDB->query($sql) ;
if ($inDB->num_rows($result)){
$items = array();
while ($item=$inDB->fetch_assoc($result)){
$items[]=$item;
}
}
$smarty = $inCore->initSmarty('modules', 'mod_gdspec.tpl');
$smarty->assign('items', $items);
$smarty->display('mod_gdspec.tpl');
return true;
}
?>
模板mod_gdspec.tpl:
{foreach item=item from=$items}
<div class="mod_latest_entry">
<div class="mod_latest_f_gdpec">
{$item.f_gdpec}
</div>
<div class="mod_latest_w_gdpec" >
{$item.w_gdpec}
</div>
</div>
{/foreach}
来自tabditsy的数据没有出现,我无法理解多少。 问你的力量。 感谢您的关注。
更正的脚本-module.php !!!!!!!!!!!!!
您正在分配值之前返回值,请删除该不必要的返回值
<?php
function mod_gdspec($module_id){
$inCore = cmsCore::getInstance();
$inDB = cmsDatabase::getInstance();
$cfg = $inCore->loadModuleConfig($module_id);
$sql = "SELECT f_gdpec,
w_gdpec,
url_gdpec,
p_gdspec
FROM cms_gdspec";
$result = $inDB->query($sql) ;
if ($inDB->num_rows($result)){
$items = array();
while ($item=$inDB->fetch_assoc($result)){
$items[]=$item;
}
}
// return true;------------>remove this
$smarty = $inCore->initSmarty('modules', 'mod_gdspec.tpl');
$smarty->assign('items', $items);
$smarty->display('mod_tags.tpl');
return true;
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.