Stephan,
Actually I have successfully been running banner adds on my phprunner sites. I never did get the random feature going, I just simply start with the first image and work my way through with each refresh. A couple of other fields you may want to consider is a sort field and a weight field in your banner table. The sort can be used to order the banners for display and the weight would be good so you could define a routine to set a banner to show every fifth time, for example.
BUT, all my work was done using phprunner 3.0 and will be pretty useless for the new version.
What I did was created a file get_banners_2w.php ( 2 banners width wise )
Code as below
=========================
<?php // start of file ?>
<?php $debug=0; ?>
<table width="100%" cellpadding="0px" cellspacing="0px" border="0px">
<tr>
<?php
global $conn;
$go_url_title = '';
$go_url = '';
$ctr = 0;
$banner_ctr =0;
$strSQL1 = "select `purchase_id`, `customer_id`, `group`, `inventory_id`, `banner`, `banner_url` From `purchases` where ((`purchases`.`group` = 'Advertising') AND (`purchases`.`purchase_date` <= now()) AND (`purchases`.`product_id` != 1) AND (`purchases`.`purchase_id` < '".$_SESSION["last_side_banner"]."')) order by `purchase_id` DESC limit 2";
$rsSQL1 = db_query($strSQL1,$conn);
$done ="no";
while($data1=db_fetch_array($rsSQL1))
{
$_SESSION["last_side_banner"] = $data1["purchase_id"];
$ctr += 1;
$banner_ctr +=1;
$align_gif = "align=\"left\"";
if ($ctr <=2)
{
if ($ctr > 1) $align_gif = "align=\"right\"";
$i=70;
$value=$data1["banner"];
if ($data1["banner_url"])
{
$go_url = "window.open('http://".$data1["banner_url"]."';)";
$go_url_title ="Visit this advertisers web site at ".$data1["banner_url"]." (Opens in a new window)";
}
else
{
$go_url = "document.location.href='advertisers_rates.php'";
$go_url_title ="Get the information about Advertising in the Yellow Sheet";
}
if($debug == 1)
{
$go_url_title = "Debug Advertiser ".$data1["banner_url"]." Invoice: ".$data1["purchase_id"];
}
echo "\r\n<td colspan=\"2\" valign=\"bottom\" width=\"50%\" ".$align_gif." ><table cellpadding=\"0px\" cellspacing=\"0px\" border=\"0px\"><tr><td>";
$key = $data1["purchase_id"];
$iquery="field=".$i."&key=".htmlspecialchars($key);
$disp='<img border="0" src="get_side_banners_imager.php?'.$iquery.'" onclick="'.$go_url.'" title="'.$go_url_title.'" alt="'.$go_url_title.'" />';
echo $disp;
echo "\r\n</td></tr></table></td>";
$done ="no";
}
}
if ($banner_ctr == 0)
{
$_SESSION["last_side_banner"] = 999999;
$go_url = "document.location.href='advertisers_rates.php'";
if($debug == 1)
{
$go_url_title ="Debug Mode First Banner holder.";
}
else
{
$go_url_title ="Get the information about Advertising in the Yellow Sheet.";
}
echo "<td valign=\"bottom\" width=\"50%\" align=\"left\"><table cellpadding=\"0px\" cellspacing=\"0px\" border=\"0px\"><tr><td>";
echo "<img src=\"images/no_logo_1.gif\" border=\"0px\" onclick=\"".$go_url."\" title=\"".$go_url_title."\" alt=\"".$go_url_title."\" />";
echo "</td></tr></table></td>";
$banner_ctr = 1;
}
if ($banner_ctr <= 1)
{
$_SESSION["last_side_banner"] = 999999;
$go_url = "document.location.href='advertisers_rates.php'";
if($debug == 1)
{
$go_url_title ="Debug Mode Last Banner holder.";
}
else
{
$go_url_title ="Get the information about Advertising in the Yellow Sheet.";
}
echo "<td valign=\"bottom\" width=\"50%\" align=\"right\"><table cellpadding=\"0px\" cellspacing=\"0px\" border=\"0px\"><tr><td>";
echo "<img src=\"images/no_logo_2.gif\" border=\"0px\" onclick=\"".$go_url."\" title=\"".$go_url_title."\" alt=\"".$go_url_title."\" />";
echo "</td></tr></table></td>";
}
?>
</tr>
</table>
<?php // end of file ?>
=================
Then in my supertop.php I inserted the snippet below.
=================
<table style="border: 0px solid orange; padding:0px; margin:0px auto; width:100%;" cellspacing="0px">
<tr>
<td>
<?php
if(file_exists("get_banners_2w.php"))
{ include("get_banners_2w.php");}
?>
</td>
</tr>
</table>
=================
Finally in my _list.php template, I just added the snippet below to call the file.
=================
<?php
if($_SESSION["GroupID"] == 'Customer' && file_exists("include/supertop_customer_print.php"))
include("include/supertop_customer_print.php");
?>
=================
My goal was to get banner advertising happening on all my Customer views and print pages. This works quite nicely and is all generated with PHPRunner 3.0 when I hit the build button. If I get time, I would indeed like to add random and weights to the function, but time is just to short right now.
I hope this gives you an idea or a helpfull hint but again its all using the old version of PHPRunner. When the smarty template method came into play, there was too much code to modify for me to upgrade so I have just stuck with the old version until I can get time to build a new project with the new stuff.
Im sure support will suggest a more elegant way and hopefully even include a banner ad feature in future releases.
A couple of notes, I was using ajax at first to get the banner ads going, but it was acutally a larger hit on the bandwidth and a few older browser incompatibilities that pulled me back to just using phprunner templates and code to make it work. And it works quite nicely. Second, all my clicks on the banners, open the advertiser in a new or blank window. I use SSL on my sites and opening a page that is not secure, from a secure web page brings up to many warnings that only confuse the user.
Hope this helps somewhat. You can actually go to www.yellowsheet.ca and see all this in action. THe pages you see before you log in have banner ads displaying, they are displayed 2 deep in the right hand side. Once inside as a customer, you will see the banner ads 2 wide across the top of any print outs and reports.