Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

random ad banners in PHP

General discussions related to php

Moderators: macek, egami, gesf

Postby Redcircle » Tue Jan 28, 2003 11:31 pm

where is the information on the banners stored. in a database or what..

You can make an array and randomly access the content.

see for more info.
User avatar
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

Postby Oleg Butuzov » Wed Jan 29, 2003 12:54 am

You must create table with banners nanners id links images...

after that use rand() function of rand query to show tha banner..
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby furiousweebee » Fri Feb 14, 2003 10:13 pm

Could you please give me more information?

I was hoping it would be as simple as a command along the lines of:

select rand() from $table_name

or something like that.

I have a table with fields: id, banner_imgurl, banner_link, and banner_alttext

I just want to work out how to randomly pull one record from this database for a banner rotation system on my site. Also in the future I would like to be able to set a priority for each entry, so that a priority rating of (for example) 100, would appear about 100 times as often as something with a rating of one. Any help would be great.
New php-forum User
New php-forum User
Posts: 7
Joined: Fri Feb 14, 2003 10:10 pm

Postby furiousweebee » Sat Feb 15, 2003 3:16 pm

Ok here's what I've got: (sorry for the length)
$db_name = "******";
$table_name = "advertising";

$connection = @mysql_connect("localhost", "******", "******")
or die("Couldn't connect.");

$db = @mysql_select_db($db_name, $connection)
or die("Couldn't select database.");

$sql = "SELECT id, banner_url, banner_h, banner_w, banner_alt, banner_link
FROM $table_name
ORDER by rand() LIMIT 1

$result = @mysql_query($sql,$connection)
or die("Couldn't execute query.");

while ($i < $num) {


Then putting the variables into the page:

<a href="http://<? echo "$banner_link"; ?>" target="_blank"><img src="http://<? echo "$banner_url"; ?>" width="<? echo "$banner_w"; ?>" height="<? echo "$banner_h"; ?>" alt="<? echo "$banner_alt"; ?>" border="0"></a>

Then iterating




So can anyone tell me where I've gone wrong? I'm a bit of a novice, sorry.
New php-forum User
New php-forum User
Posts: 7
Joined: Fri Feb 14, 2003 10:10 pm

Postby Hurkle » Wed Feb 19, 2003 7:49 am

It looks like the approach you're using is just about right. I suspected that you might not be getting true randomness, as you're not seeding the rand() function. I did a quick search, and found this post which explains one thing to try quite elegantly. Rather than pasting the text, I'll just give you the link, so you can see the whole thing in context. Hope this helps.
New php-forum User
New php-forum User
Posts: 36
Joined: Tue Jan 07, 2003 8:45 am
Location: Minnesota, USA

Postby furiousweebee » Tue Mar 25, 2003 5:30 pm

Hi, thanks for that! You've been a big help.

For some reason I was never emailed about a reply to this topic.... oh well. Thanks!
New php-forum User
New php-forum User
Posts: 7
Joined: Fri Feb 14, 2003 10:10 pm

Return to PHP General

Who is online

Users browsing this forum: No registered users and 5 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.