我的SQL函数返回对未定义函数错误的调用

时间:2015-10-31 13:03:24

标签: php

我正在尝试根据以下条件显示广告:

  • Active Adverts = 6,运行showActiveAdvert()功能
  • 有效广告!= 6,运行getActDefault()功能
  • Active Adverts = 0,运行getDefaultBanner()功能

现在的问题是,当我按照它的方式运行此函数时,它会返回Fatal error: Call to undefined function getDefaultBanner() in /home1/xxxxxxx/public_html/skin/widgets/myAdServer.php on line 47。我试图嵌套最后一个函数getDefaultBanner(),但它没有显示任何内容。

我如何纠正这个问题?

以下是功能:

function showActiveAdverts() {
    $status = 1;
    //Build final queries.
    $query = mysql_query("SELECT * FROM fpf_adverts WHERE 
        status = '".mysql_real_escape_string($status)."'
        ORDER BY rand() LIMIT 6 ") or die(mysql_error());

        $count = mysql_num_rows($query); $row = mysql_fetch_assoc($query);

        if ($count >= 1) {
            do {
                $list[] = $row['id'];
            } while ($row = mysql_fetch_assoc($query));
            return $list;
        } else {
            return FALSE;
        }
    }

    function getActDefault() {
        $status1 = 1;
        $status2 = 6;
        //Query DB for both active and default adverts
        $query = mysql_query("(SELECT * FROM fpf_adverts WHERE status = '".mysql_real_escape_string($status1).
            "' ORDER BY rand()) UNION ALL  (SELECT e.*FROM fpf_adverts e JOIN fpf_adverts ee ON e.status + 6 > ee.status WHERE e.status = '".mysql_real_escape_string($status2).
            "') LIMIT 6 ") or die(mysql_error());

        $count = mysql_num_rows($query);
        $row = mysql_fetch_assoc($query);

        if ($count >= 1) {
            do {
                $list[] = $row['id'];
            } while ($row = mysql_fetch_assoc($query));
            return $list;
        } else {
            return FALSE;
        }
    }

    function getDefaultBannner() {
        $status = 6;
        $query = mysql_query("SELECT e.* FROM fpf_adverts e JOIN fpf_adverts ee ON e.id + 6 > ee.id WHERE e.status = 
            '".mysql_real_escape_string($status)."'
            LIMIT 6 ") or die(mysql_error());

            $count = mysql_num_rows($query); $row = mysql_fetch_assoc($query);

            if ($count >= 1) {
                do {
                    $list[] = $row['id'];
                } while ($row = mysql_fetch_assoc($query));
                return $list;
            } else {
                return FALSE;
            }
        }

这是我用来循环的功能,以便它可以显示在前端:

<?php
$showBoard_arr = showActiveAdverts();
//Defining this before the first function, in case no results.
$countBoard    = 0;
$advertTop .= '<div class="adSlot">';
$advertBottom .= '<div class="adSlot">';

if ($showBoard_arr) {
    foreach ($showBoard_arr as $key => $showBoard) { //Get information from my DB
        $countBoard += 1;
        $advertId       = getAdLocation($showBoard, 'id');
        $advertTitle    = getAdLocation($showBoard, 'title');
        $advertImg      = refineProfileImage(getAdLocation($showBoard, 'img_url'));
        $advertUrl      = $site_path . "clicks/" . $board_slug . "/" . $advertId;
        $activeBoardIds = getAdLocation($showBoard, 'board_id');
        if ($countBoard <= 3) {
            $advertTop .= '<a href="' . $advertUrl . '" rel="nofollow"><img src="' . $site_path . "banners/" . $advertImg . '"></a>';

        } else {
            $advertBottom .= '<a href="' . $advertUrl . '" rel="nofollow"><img src="' . $site_path . "banners/" . $advertImg . '"></a>';
        }
    }
    //The first foreach is ended, now I check if there were not 6 adverts.
    if ($countBoard != 6 && $countBoard > 0) { //If there are NOT exactly 6 adverts.
        $countBoard    = 0;
        $advertTop     = '<div class="adSlot">';
        $advertBottom  = '<div class="adSlot">'; //Empty the first function adverts.
        $showBoard_arr = getActDefault(); //Get the adverts from this function.
        //Repeating foreach statement.
        foreach ($showBoard_arr as $key => $showBoard) { //Get information from my DB
            $countBoard += 1;
            $advertId       = getAdLocation($showBoard, 'id');
            $advertTitle    = getAdLocation($showBoard, 'title');
            $advertImg      = refineProfileImage(getAdLocation($showBoard, 'img_url'));
            $advertUrl      = $site_path . "clicks/" . $board_slug . "/" . $advertId;
            $activeBoardIds = getAdLocation($showBoard, 'board_id');
            if ($countBoard <= 3) {
                $advertTop .= '<a href="' . $advertUrl . '" rel="nofollow"><img src="' . $site_path . "banners/" . $advertImg . '"></a>';

            } else {
                $advertBottom .= '<a href="' . $advertUrl . '" rel="nofollow"><img src="' . $site_path . "banners/" . $advertImg . '"></a>';
            }
        }
    }
}
//So if we are here there are 2 options: 1) First or second function done.
//2) No results so we need the third function to be called.
if ($countBoard == 0) { //If there are no results at all.
    $showBoard_arr = getDefaultBanner(); //Get adverts from this other function.
    //Repeating foreach statement.
    foreach ($showBoard_arr as $key => $showBoard) { //Get information from my DB
        $countBoard += 1;
        $advertId       = getAdLocation($showBoard, 'id');
        $advertTitle    = getAdLocation($showBoard, 'title');
        $advertImg      = refineProfileImage(getAdLocation($showBoard, 'img_url'));
        $advertUrl      = $site_path . "clicks/" . $board_slug . "/" . $advertId;
        $activeBoardIds = getAdLocation($showBoard, 'board_id');
        if ($countBoard <= 3) {
            $advertTop .= '<a href="' . $advertUrl . '" rel="nofollow"><img src="' . $site_path . "banners/" . $advertImg . '"></a>';

        } else {
            $advertBottom .= '<a href="' . $advertUrl . '" rel="nofollow"><img src="' . $site_path . "banners/" . $advertImg . '"></a>';
        }
    }
}

//Now we are done, for x, y or z, the adverts are loaded. So we show them.
$advertTop .= '</div>';
$advertBottom .= '</div>';

echo $advertTop;
?>

1 个答案:

答案 0 :(得分:1)

更改

 function getDefaultBannner()

 function getDefaultBanner()  // has just only one N

...问候

相关问题