2014-05-20 2 views
-5

의 세 파일이 있습니다. classes/header_featured.phpPHP 함수를 호출 할 수없고 결과를 표시 할 수 없습니다.

<?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, 내가 파일 "클래스/header_featured.php"하는 내가 만든이 이처럼 내 웹 사이트 헤더에 등장하는 광고를 게재하려면 무엇 기본적으로 내가 원하는

{foreach item=item from=$no_featured} 
    {$item.ad_id} 
    {$item.ad_title} 
    {$item.img_id} 
    {$item.ad_img} 
    {$item.img_folder} 
{/foreach} 

데이터베이스에서 fetchings 행과 그럼 내가 기능 광고의 기능을 호출하고 smarty 파일 "템플릿/h_featured.html"에 변수를 할당하는 루트 "h_featured.php"에있는 다른 파일을 만들었지 만 그것은 나를 위해 작동하지 않는 그것은 아무런 표시 또는 전화가없는 것처럼 보이지 않습니다. 기능이나 데이터없이 할당 ...

도와주세요 ..

+1

1) 불쌍한 디자인. 2) mysql_ * 함수를 사용하지 마십시오. 3) getfeatured() 함수에서 아무 것도 반환하지 않습니다 (낙타하십시오) – Noah

+0

지적 해 주셔서 고맙습니다.하지만 제 문제에 대한 해결책을 줄 수 있습니까? – user3305677

+0

적절한 명명 규칙, 사용자 정의 함수, 준비된 SQL 문 등을 배우는 것이 더 낫습니다.이 경우에는 단순히 대답을 – Noah

답변

3

귀하의 방법 retu하지 않습니다 getfeatured 아무것도 아니야. 따라서 $featured_ads은 비어 있습니다. 파일 클래스에서

+0

에게 건네지 않으므로 어떻게해야합니까? 코드를 완료 할 수 있습니까? ... – user3305677

0

은/header_featured.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; 
      } 
      return $ads; 
     } 
    } 
?> 
+0

성공하지 못함 ... 다른 코드가 괜찮다고 생각하십니까 ... – user3305677

+0

감사합니다 ... $ obj = new header_featured(); $ ads = $ obj-> getfeatured(); $ smarty-> assign ('ads', $ ads); – user3305677

관련 문제