中有三個文件 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