I am trying to code some advertising banners on my page based on random picks from a table in my DB. I have successfully got my top banner to display and log an impression:

// Top Banner
$query="SELECT * FROM sm_ADS WHERE id_Maze_Category='$Category_ID' and Type='large' and Active='1' ORDER BY RAND() LIMIT 1";
$result=mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result);
$sql="INSERT INTO sm_History (AD_ID, User_ID, Type) VALUES ('$AD_ID','$User','$Type')";
$result = mysql_query($sql) or die(mysql_error());
$TopBanner = "<A HREF=\"image_click.php?url={$row["URL"]}&id={$AD_ID}\" TARGET=\"_blank\""." BORDER=\"0\"><img src=\"/ADS/{$row["file_name"]}\" alt=\"\"/></A>";

I just enter the $TopBanner where it needs to go in my page.

Using the same logic above, I need to choose 3 smaller banners to display of the side of my page with goal that I produce 3 variables called:


the query needs to be this:

$query="SELECT * FROM sm_ADS WHERE id_Maze_Category='$Category_ID' and Type='small' and Active='1' ORDER BY RAND() LIMIT 3";

I, also, need to LOG each impression of the 3 small banners similar to the top banner.

I think I can grunt my way through this, but would sure appreciate some assistance to find a quick way to do this. Thanks!

8 Years
Discussion Span
Last Post by matthewl

the three banners you want to display could use similar code as your top banner. I know this next idea is a bit off topic but can I recommend using AJAX/PHP/MYSQL to handle retrieving the banner and log user info like browser used ,the member id, etc? You can even use Interval() at the bottom of the javascript function that will reload the function to display a new banner. In my opinion javascript is better suited in handling banner advertisements then php alone. I am sorry that I ambitious to write an ajax script that would serve and log info you want. Anyways I'll give you an example of an AJAX script that would request a php page and pass info via GET form data. Though you can pass info using POST form data using the send function under the open function and changing GET to POST.

<script type="text/javascript">
function init() {
var httpRequest;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
    httpRequest = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
} else {
  alert("Your browser does not support XMLHTTP!");
        document.getElementById('display').innerHTML= httpRequest.responseText;


httpRequest.open("GET", "phppage.php?var1=vardata&var2=vardata", true);

As you seen I placed the the output of the php file into an element with the id of 'display'. in my html file I have a div that would display what the php sends via the AJAX request. if you use this code I would recommend changing the element id to something else like 'topbanner' and use a span as the location to display the banner.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.