-1
我試圖顯示基於以下條件廣告打電話:我的SQL函數返回未定義的函數錯誤
- 主動廣告= 6,運行
showActiveAdvert()
功能 - 主動廣告= 6,運行
getActDefault()
功能 - 主動廣告= 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;
?>
這兩段代碼是否在同一個文件中?如果他們不是,你需要「包括」他們(*服務器的路徑*)。 – Qirel
我已經包括他們,其他功能正在工作,除了'getDefaultBanner()' –
這裏的證明?用'include'發佈你的文件名和更新後的代碼,然後 – Alex