Php My SQL函数返回对未定义函数错误的调用
我试图根据以下条件显示广告:Php My SQL函数返回对未定义函数错误的调用,php,Php,我试图根据以下条件显示广告: 活动广告=6,运行showActiveAdvert()函数 活动广告!=6,运行getActDefault()函数 活动广告=0,运行getDefaultBanner()函数 现在的问题是,当我按原样运行此函数时,它返回致命错误:调用第47行/home1/xxxxxxx/public\u html/skin/widgets/myAdServer.php中未定义的函数getDefaultBanner()。我尝试嵌套最后一个函数getDefaultBanner(),
- 活动广告=6,运行
函数showActiveAdvert()
- 活动广告!=6,运行
函数getActDefault()
- 活动广告=0,运行
函数getDefaultBanner()
致命错误:调用第47行/home1/xxxxxxx/public\u html/skin/widgets/myAdServer.php中未定义的函数getDefaultBanner()。我尝试嵌套最后一个函数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;
?>
更改
function getDefaultBannner()
为了
关于…这两段代码是否在同一个文件中?如果没有,您需要包含它们(使用服务器的路径)<代码>getDefaultBannner
!=getDefaultBanner
。函数的实际名称拼写错误。@Qirel eagle eye!:-)谢谢@Qirel。我去买一副自己的眼镜。@SamuelAsor打字错误在每个人身上都会发生,并不总是那么容易被发现。。眼镜可能有用,也可能没用!;)
function getDefaultBanner() // has just only one N