Location: PHPKode > projects > ProPHP > ProPHP/show.php
<?php
	/*****************************************************************
	************* BKWORKS PRO PHP V 0.5 BETA 1 ***********************
	******************** BRYAN KOOIENGA ******************************
	****************** DECEMBER 20, 2007 *****************************
	*****************************************************************/
# Gets the information given by the calling webpage.
$customer = $_GET['customer'];
$wid = $_GET['width'];
$height = $_GET['height'];

include("include/db_info.php"); # This is our database information file.
$query = "SELECT * FROM ads WHERE width = '$wid' AND height='$height' AND site_number != '$customer'"; # Checks for any and all ads that have these size dimensions.
$results = mysql_query($query) or die("Can't query because " . mysql_error());
$num_of_ads = mysql_num_rows($results); # Lets us know how many ads we have to work with.
if($num_of_ads == 0) { # If there are none, then we still have to show something. How about a placeholder?
	if($height == 240) {
		$img = "placeholder_120x240.jpg";
	} elseif($height == 60) {
		$img = "placeholder_468x60.jpg";
	} elseif($height = "120") {
		$img = "placeholder_600x120.jpg";
	}
	$ads[1]['url'] = $img;
	$ads[1]['alt'] = "BKWorks ProPHP Ad Placeholder";
	$ads[1]['ad_num'] = 0;
	$random_int = 1;
} else { # If there are more than one, then we sit here and look at each one individually.
	for($intX = 1; $intX <= $num_of_ads; $intX++) {
		$working_var = mysql_fetch_array($results);
		$ads[$intX]['num'] = $working_var['site_number'];
		$ads[$intX]['url'] = $working_var['image'];
		$ads[$intX]['alt'] = $working_var['alt_text'];
		$ads[$intX]['ad_num'] = $working_var['ad_number'];
	}
	$random_int = rand(1,$num_of_ads); # Now we pick one.
}
/***************************************************************
Asking the databse how many ad serves the customer has had
***************************************************************/
$query = "SELECT ad_servs FROM sites WHERE site_number = '$customer'";
$results = mysql_query($query) or die("Can't query because " . mysql_error());
$results = mysql_fetch_array($results);
$results['ad_servs'] += 1;
$query = "UPDATE sites SET ad_servs = '$results[ad_servs]' WHERE site_number = '$customer'"; # Adds one and adds it to the database.
mysql_query($query) or die("Can't query because " . mysql_error());
/*************************************************************/

$query = "SELECT install_url FROM settings"; # We have to tell the javascript where it's located.
$results = mysql_query($query) or die("Can't query on line " . __LINE__ . " because " . mysql_error());
$site_url = mysql_fetch_object($results);
$site_url = $site_url -> install_url;

header('Content-type: application/x-javascript'); # Now we trick the browser into thinking that it's actually opening a javascript.
?>
document.write('<center><a href="<?php echo $site_url; ?>/count.php?num=<?php echo $ads[$random_int]['ad_num']; ?>"><img src="<?php echo $site_url; ?>/ads/<?php echo $ads[$random_int]['num']; ?>/<?php echo $ads[$random_int]['url']; ?>" width="<?php echo $wid; ?>" height="<?php echo $height; ?>" alt="<?php echo $ads[$random_int]['alt']; ?>" border="0"></a></center><br /><br />');
Return current item: ProPHP