dynamic random images WITHOUT refresh (banner ads)

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 6
Joined: Tue Apr 01, 2003 5:20 pm
Location: Las Vegas

Wed Apr 23, 2003 10:47 am

I can't believe there isn't a solution for this on the web, but after about an hour and a half of searching and reading, I decided, I'd ask about it here.

Yes, I have seen the post about banner rotation on here and when followed it does produce "random" banner ads, but only ONCE - when the page is first loaded or when the page is refreshed. What about banner ads that change without a refresh or loading a new page? I currently have JavaScript running on my pages that accomplishes just that. However when I tried to import that code into my .php pages, it fails to display the images, which I believe has to do with the single quotes(') vs double quotes(") issue of php programming. IS THERE A WAY OF MAKING THIS JAVASCRIPT WORK IN PHP? (sorry for the caps).

I mentioned my problems to a colleague who doesn't know php, but is very adept at Perl/CGI/JS and he mentioned that I probably need to have a socket open to dynamically display the banners without the user changing anything. Any ideas?

PS: The images really don't need to be random - they should cycle through sequentially.

User avatar
New php-forum User
New php-forum User
Posts: 21
Joined: Tue Apr 22, 2003 10:02 pm
Location: South Africa, JHB

Wed Apr 23, 2003 10:09 pm

Hozit sincitybrant.

Have you tried to look for something with active X controls.
I am using it to send sql queries to the database without refreshing the page.

I bet it will work with images as well.
But the tricky part will be getting the different images.

Maybe java script ???

Here is some of the code.

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<object id=objPicture classid="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83" border=0 width=0 height=0 VIEWASTEXT>
<param name=DataURL value="">
<param name=UseHeader value="True">
<param name=CaseSensitive value="False">
<param name=CharSet value="windows-1252">

<script language="javascript">
function PictureData() {
objPicture.DataURL ="Picture.php?Where= /* no of pic to send */";
}//End Function


<body bgcolor="#FFFFFF">
<form name="picture" method="post">
<center><h2>Picture Change</h2>
<table border=0 cellpadding=2 cellspacing=2>
<table id=tblPicture datasrc=#objPicture border=0 cellspacing=0 cellpadding=0>
<tr id=DataRowPicture bgcolor="#ffffff">
<td width='150pi'>
<span dataformatas='html' datafld="PLabel"></span>

On page Picture.php
The code to get the different pictures.

if (db_con()) {
$sqlstr = "SELECT FROM DATABASE Picture url or pictures WHERE pic_id = $Where";
$result = mysql_query($sqlstr,$db_conn);
echo "";
if ($myrow = mysql_fetch_array($result)) {
echo "PLabel \n";
$OutputVar = "<img src=’images/";
do {
$OutputVar = $OutputVar."$myrow[‘pic or url’]";
} while ($myrow = mysql_fetch_array($result));
$OutputVar = $OutputVar."’ atl=’picture changer’>\n";
echo $OutputVar;
}//End If myrow
} //End If db_con

note the javascript will not work in this page.
I have tried

Make your javascript execute the PictureData();

And send random numbers or url’s up to you.

Yell if you need more help

:o :!: :!:

New php-forum User
New php-forum User
Posts: 6
Joined: Tue Apr 01, 2003 5:20 pm
Location: Las Vegas

Tue Apr 29, 2003 3:22 pm

While I was waiting for a response, I tried a number of things, but one thing that I stuck with (because it worked) was separating out my HTML from my PHP. So I have more <?php ?> tags on each page, but that allowed the JavaScript to execute properly. Thank you for your response, but your response also relies upon JS, so it would have been the same problem. I would like to help people with their problems, but I am still too new at this and actually am going to post another problem.

Post Reply