Using DB class from PHPLIB
| From: | Get Now | Date: | Sun, 19 Nov 2000 00:01:11 +0000 |
| Subject: | Using DB class from PHPLIB | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-26084@lists.php.net to get a copy of this message | ||
Hello All,
I am using banner code written by John Coggeshall. But somehow DB class from
PHPLIB are not working and I am getting following error. Please see the code
below and help me out to fix this problem.
Fatal error: Call to a member function on a non-object in banner.php on line
39
Any help is greatly appreciated. Thanks in advance.
regards,
SK
Code:
<?php
// Check to see if the banner ID flag is set
if(isset($_bannerID)) {
// Create an instance of the Database Layer
$DB = new DB_BANNER;
// Get info about banner from DB
$DB->query("SELECT * FROM banner WHERE(uniqueid=$_bannerID)");
// Check to see if Banner ID is valid before doing
// anything else
if($DB->num_rows() != 0) {
// Increment Click Counter
dbIncClks($_bannerID);
// Redirect user to new location, $_query_extra
// is the Extra parameters that were given to the
// script back in dbShowBan(). This feature is
// for if you want a banner on your own site, to
// your own site, but use sessions and don't want
// the user to lose their session when they
// click.
$url = $DB->f("URL"). $_query_extra;
Header("Location: $url");
}
}
function Display_Banner($bannerID = "none", $query_extra = "") {
// Grab the Database Layer and the Config options
global $DB, $_bannercfg, $PHP_SELF;
// Did we pass a BannerID?
if($bannerID == "none") {
// If Not, Grab the next in rotation
// First, make sure that there is something to select
$DB->query("SELECT * FROM banner WHERE pos='' LIMIT 1"); // ERROR ON
THIS LINE
// If there is nothing, then everything has
// been displayed
// Time to start from square 1
if($DB->num_rows() == 0) {
$DB->query("UPDATE banner SET pos='' WHERE(pos='A')");
}
// Finally, select the next banner
$DB->query("SELECT * FROM banner WHERE(pos='') ORDER BY b_order LIMIT 1");
} else {
// If so, Grab the requested Banner
$DB->query("SELECT * FROM banner WHERE(ID='$bannerID')");
}
// Make sure we grabbed something
if($DB->num_rows() == 0) {
return false;
}
$DB->next_record();
// Saved the data we got in a separate array
$ban_data = $DB->Record;
// Construct the HTML for the GET
$get = "?_bannerid=".urlencode($ban_data['ID']);
// Make the extra query string
if(is_array($query_extra)) {
foreach($query_extra as $key => $val) {
$get .= "&$key=".urlencode($val);
}
}
// Construct the HTML for the banner and include the GET // we constructed
previously.
$html = "<A HREF='$PHP_SELF$get'>"
. "<IMG SRC='$_bannercfg[srcpath]$ban_data[SRC]' "
. "ALT='$ban_data[ALT] "
. "BORDER='$_bannercfg[border]'>"
. "</A>";
// Increment the hits
dbIncHits($ban_data['ID']);
// Flag the banner used as displayed (if it was selected
// by rotation) In special cases, we're not going to flag
// anything
if($bannerID == "none") {
$DB->query("UPDATE banner SET pos='A'
WHERE(ID='".$ban_data['ID']."')");
}
// Finally, echo the HTML
echo $html;
// Return True
return true;
}
function dbIncClks($_bannerID) {
global $DB;
$DB->query("SELECT clicks FROM banner WHERE(ID='$_bannerID')");
If($DB->num_rows() == 0) {
return false;
}
$DB->query("UPDATE banner SET clicks=".($DB->f('clicks')+1)."
WHERE(ID='$_bannerID')");
}
function dbIncHits($_bannerID) {
global $DB;
$DB->query("SELECT hits FROM banner WHERE(ID='$_bannerID')");
If($DB->num_rows() == 0) {
return false;
}
$DB->query("UPDATE banner SET hits=".($DB->f('clicks')+1)."
WHERE(ID='$_bannerID')");
}
?>