Hello, I'm working on this ad script and normally it works fine but on our webpage there's a search function and when you try to do a search it gives this error
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/web/ac/news/showarchive.php on line 50
There is nothing on line 50 of showarchive.php and it works fine if I'm not trying to include this new adsystem into our templates.
We would call the ad by this
require("/home/web/ac/admanager/phpadmentor_config.php");
?>
<center><? echo(PhpAdMentor_GetAd("7", 2, 0) ); ?></center>
That part of the code would be included in our header file.
the admentor_config file is below. All the click and impression tracking has been disabled since we do not want it tieing up the database.
Hope someone can help me!
<?
$sPhpAdMentor_InstallPath = "http://ac.warcry.com/admanager/";
$sPhpAdMentor_DBHost = "localhost";
$sPhpAdMentor_DBUser = "da_cod";
$sPhpAdMentor_DBPassword = "ugo4win";
$sPhpAdMentor_DBDatabase = "admanager";
$sPhpAdMentor_DefaultBanner = "http://www.aspcode.net/images/aspcode46860.gif";
$sPhpAdMentor_DefaultClick = "http://www.aspcode.net/";
//$PhpAdMentor_admin_user = "stefan";
//$PhpAdMentor_admin_pass = "stefan";
$sPhpAdMentor_MaxInt = 2147483647;
$sPhpAdMentor_MaxDate = "2020-10-10";
function PhpAdMentor_MaxIntToNull( $val )
{
global $sPhpAdMentor_MaxInt;
if ( $val == $sPhpAdMentor_MaxInt )
return "";
return $val;
}
//Do not modify functions below...
function PhpAdMentor_GetDatabaseConn()
{
global $sPhpAdMentor_DBHost;
global $sPhpAdMentor_DBUser;
global $sPhpAdMentor_DBPassword;
global $sPhpAdMentor_DBDatabase;
$conn = mysql_connect($sPhpAdMentor_DBHost, $sPhpAdMentor_DBUser, $sPhpAdMentor_DBPassword);
mysql_select_db($sPhpAdMentor_DBDatabase, $conn);
return $conn;
}
/* function PhpAdMentor_UpdateStats( $connadmentor, $id, $addclicksno, $addimpressionsno )
{
global $sPhpAdMentor_DBDatabase;
$sSQL = "select count(*) as antal from $sPhpAdMentor_DBDatabase.stats where bannerid=$id and datum=curdate()";
$oRS = mysql_query( $sSQL, $connadmentor );
$row = mysql_fetch_array($oRS);
if ( $row["antal"] != 0 )
{
//Already exists
$sSQL = "update $sPhpAdMentor_DBDatabase.stats set ";
if ( $addclicksno )
$sSQL = $sSQL . "clicks=clicks+1";
if ( $addimpressionsno )
$sSQL = $sSQL . "impressions=impressions+1";
$sSQL = $sSQL . " where datum=Now() and bannerid=$id ";
}
else
{
$sSQL = "insert into $sPhpAdMentor_DBDatabase.stats( bannerid,datum,clicks,impressions ) values($id, Now() ";
if ( $addclicksno )
$sSQL = $sSQL . ",1";
else
$sSQL = $sSQL . ",0";
if ( $addimpressionsno )
$sSQL = $sSQL . ",1";
else
$sSQL = $sSQL . ",0";
$sSQL = $sSQL . ")";
}
mysql_query( $sSQL, $connadmentor );
$sSQL = "update $sPhpAdMentor_DBDatabase.banner set showcount=showcount+";
if ( $addimpressionsno )
$sSQL = $sSQL . "1";
else
$sSQL = $sSQL . "0";
$sSQL = $sSQL . ",clickcount=clickcount+";
if ( $addclicksno )
$sSQL = $sSQL . "1";
else
$sSQL = $sSQL . "0";
$sSQL = $sSQL . " where bannerid=$id";
mysql_query( $sSQL, $connadmentor );
}
*/
function AdSQL_AddAndWhere( $sWhere, $sWhat )
{
$sRet = "";
if ( $sWhere == "" )
$sRet = " WHERE ";
else
$sRet = $sWhere . " AND ";
$sRet = $sRet . " " . $sWhat;
return $sRet;
}
function PhpAdMentor_GetBanner($bid, $gifurl/, $xsize, $ysize /)
{
global $sPhpAdMentor_InstallPath;
/ if ($xsize != 0 )
$xsizestring = "width='$xsize'";
if ($ysize != 0 )
$ysizestring = "height='$ysize'"; /
$sClickUrl = $sPhpAdMentor_InstallPath . "click.php?mgr=aspcode.net&id=" . $bid;
// return "<a href='$sClickUrl' target=\"_blank\"><img border='0' src='$gifurl' $xsizestring $ysizestring></a>";
return "<a href='$sClickUrl' target=\"_blank\"><img border='0' src='$gifurl'></a>";
}
function PhpAdMentor_GetHTMLBanner( $htmlcode )
{
//Replace with special tags...
$htmlcode = stripslashes($htmlcode);
srand ((double) microtime() * 1000000);
$lastrandom ="";
$nOffset = 0;
while ( $posstart = strpos($htmlcode, "<ADM_RANDOM", $nOffset ) )
{
// echo($posstart);
//Found one, now we need to find end tag
$posend = strpos( $htmlcode, ">", $posstart+1 );
if ( !$posend )
break;
// echo($posend);
$len = $posend-$posstart;
$wholetag = substr($htmlcode, $posstart, $len+1 );
if ($wholetag == "<ADM_RANDOM-LAST>" )
{
$left = substr($htmlcode,0,$posstart);
$right =substr($htmlcode,$posend+1);
$htmlcode =$left . $lastrandom . $right;
}
else
{
$vArr = split( "-", $htmlcode );
$leftnum = $vArr[1];
$rightnum = $vArr[2];
$lastrandom = rand( $leftnum, $rightnum );
$left = substr($htmlcode,0,$posstart);
$right =substr($htmlcode,$posend+1);
$htmlcode =$left . $lastrandom . $right;
}
}
return $htmlcode;
}
function PhpAdMentor_GetAd( $sZones, $nAdPos, $nBannerId = 0, $conn=0 )
{
global $sPhpAdMentor_DBHost;
global $sPhpAdMentor_DBUser;
global $sPhpAdMentor_DBPassword;
global $sPhpAdMentor_DBDatabase;
global $sPhpAdMentor_DefaultBanner;
global $sPhpAdMentor_InstallPath;
$sSQL = "";
$sWhere = "";
if ( $conn == 0)
$connadmentor = mysql_connect($sPhpAdMentor_DBHost, $sPhpAdMentor_DBUser, $sPhpAdMentor_DBPassword);
else
$connadmentor = $conn;
$sSQL = "select distinct banner.bannerid as bannerid, gifurl, ishtml, htmlcode ";
$sSQL = $sSQL . " from $sPhpAdMentor_DBDatabase.banner ";
if ( $nBannerId != 0 )
$sWhere = AdSQL_AddAndWhere( $sWhere, "banner.bannerid=" . $nBannerId );
else
{
if( $sZones != "" )
{
$sSQL = $sSQL . ",$sPhpAdMentor_DBDatabase.banzone ";
$sWhere = AdSQL_AddAndWhere( $sWhere, "banner.bannerid=banzone.bannerid" );
$sWhere = AdSQL_AddAndWhere( $sWhere, "banzone.zoneid in ( " . $sZones . ")" );
}
if ( $nAdPos != 0 )
{
$sWhere = AdSQL_AddAndWhere( $sWhere, "banner.farmid=" . $nAdPos );
}
$sWhere = AdSQL_AddAndWhere( $sWhere, "weight > 0 and showcount < maximpressions AND validtodate >= now() AND validfromdate <= now()" );
$sWhere = AdSQL_AddAndWhere( $sWhere, " (( ishtml=1 ) OR ( clickcount < maxclicks ) )" );
}
$sSQL = $sSQL . $sWhere;
$sSQL = $sSQL . " ORDER BY weight * RAND() DESC limit 0,1";
$oRS = mysql_query( $sSQL, $connadmentor );
if ( mysql_num_rows($oRS) == 0 )
{
//default
$sClickUrl = $sPhpAdMentor_InstallPath . "click.php?mgr=aspcode.net&id=-1";
return "<a href='$sClickUrl'><img border='0' src='$sPhpAdMentor_DefaultBanner'></a>";
}
else
{
$row = mysql_fetch_array($oRS);
//Simply generate the banner html
if ($row["ishtml"] == 1 )
{
$htmlcode = PhpAdMentor_GetHTMLBanner($row["htmlcode"]);
// PhpAdMentor_UpdateStats( $connadmentor, $row["bannerid"], false,true );
return $htmlcode;
}
$htmlcode = PhpAdMentor_GetBanner( $row["bannerid"], $row["gifurl"]/*, $row["xsize"], $row["ysize"] */ );
// PhpAdMentor_UpdateStats( $connadmentor, $row["bannerid"], false,true );
return $htmlcode;
}
// not really needed mysql_close($conn);
}
/ if ( $conn == 1)
echo "Link Closed";
else
echo "link still open"; /
?>