中有三个文件 1)。 classes/header_featured.php无法调用PHP函数并无法显示结果
<?php
class header_featured{
function getfeatured() {
global $db;
$ads = array();
$featured_ads = mysql_query("SELECT * FROM class_ads where active=1 and featured=1 limit 50");
while ($temp = mysql_fetch_assoc($featured_ads)) {
$record = array();
$record['ad_id'] = $temp['id'];
$record['ad_title'] = $temp['title'];
//check for image if featured ad have image (Need to fetch only single image)
$featured_ads_images = mysql_query("select * from class_ads_pictures where ad_id={$record['ad_id']} order by order_no");
$img = mysql_fetch_assoc($featured_ads_images);
$record['img_id'] = $img['id'];
$record['ad_img'] = $img['picture'];
$record['img_folder'] = $img['folder'];
$ads[] = $record;
}
}
}
?>
2)。 h_featured.php
<?php
require_once "include/include.php";
require_once "classes/header_featured.php";
global $db;
$smarty = new Smarty;
$smarty = common($smarty);
$obj = new header_featured();
$featured_ads = $obj->getfeatured();
$smarty->assign('featured_ads ', $featured_ads);
$db->close();
if($db->error!='') { $db_error = $db->getError(); $smarty->assign('db_error',$db_error); }
$smarty->display('h_featured.html');
close();
?>
3)。模板/ h_featured.html
{foreach item=item from=$no_featured}
{$item.ad_id}
{$item.ad_title}
{$item.img_id}
{$item.ad_img}
{$item.img_folder}
{/foreach}
我想基本上是什么,我想在我的网站标题即可显示功能的广告,这样为了这个,我创建了一个文件“类/ header_featured.php”,其中我是从数据库fetchings行然后我创建了根“h_featured.php”在我打电话功能的广告功能,并指定变量Smarty的文件“模板/ h_featured.html”,但它不适合我的工作看起来像无显示或没有电话的另一个文件功能或没有数据的分配...
请帮助..
1)不好的设计。 2)不要使用'mysql_ *'函数。 3)你是不是在你的getfeatured()函数返回任何东西(请驼峰) – Noah
感谢您指出..但你可以给我解决我的问题...? – user3305677
你会做的更好,以了解正确的命名规则,用户定义的函数,准备SQL语句等。在这种情况下,我不会简单地交给你一个答案 – Noah