Author |
Message |
Mad
Junior WebHelper
Joined: 20 Feb 2003
Posts: 18
Location: England
|
Posted:
Sun Mar 02, 2003 5:33 pm (21 years, 1 month ago) |
|
I need a script that will place 3 banners with links onto a page from a list at random, i have found some but i cannot think how to make it choose 3 random ones instead of just one, any ideas? |
________________________________ www.celldamage.org |
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Sun Mar 02, 2003 5:52 pm (21 years, 1 month ago) |
|
It would be easy if you didn't care if there are duplicates, but I take it the three banners have to be different? Also, how many banners do you have in total (roughly)? |
________________________________
|
|
|
|
Mad
Junior WebHelper
Joined: 20 Feb 2003
Posts: 18
Location: England
|
Posted:
Sun Mar 02, 2003 7:49 pm (21 years, 1 month ago) |
|
I have around 30 banners, i do not want duplicates either lol,i've tried to make a code and failed lol |
________________________________ www.celldamage.org |
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Mon Mar 03, 2003 7:06 am (21 years, 1 month ago) |
|
I'm thinking it might be easier to put them all into a table, and then SELECT * FROM banners ORDER BY RAND(). Then you wouldn't have any duplicates and they would be randomly ordered. What do you think? |
________________________________
|
|
|
|
Mad
Junior WebHelper
Joined: 20 Feb 2003
Posts: 18
Location: England
|
Posted:
Mon Mar 03, 2003 4:20 pm (21 years, 1 month ago) |
|
Would that select 3? If yes go ahead! Sorry, i don't have much PHP knowledge |
________________________________ www.celldamage.org |
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Mon Mar 03, 2003 5:14 pm (21 years, 1 month ago) |
|
OK, create the following database:
Code: | CREATE TABLE banners (
id int(2),
banner_src varchar(255) NOT NULL,
banner_url varchar(255) NOT NULL,
PRIMARY KEY (id)
); |
Then access it using:
Code: | $server = "localhost";
$db_user = "...";
$db_pass = "...";
$database = "...";
$db = mysql_connect($server, $db_user,$db_pass);
mysql_select_db($database,$db);
$query = "SELECT * FROM banners ORDER BY RAND() LIMIT 3";
$query = mysql_query($query, $db);
while ($row = mysql_fetch_array($query, MYSQL_ASSOC)) {
print('Banner URL: '.$row['banner_url'].' Banner SRC: '.$row['banner_src']);
} |
You'll have to change the printed code of course to something like <a href="url"><img src="src" /></a>. |
________________________________
|
|
|
|
Mad
Junior WebHelper
Joined: 20 Feb 2003
Posts: 18
Location: England
|
Posted:
Mon Mar 03, 2003 5:38 pm (21 years, 1 month ago) |
|
where do i put in the banners?
how would i make a link to go with each link?
this is an affilates list btw |
________________________________ www.celldamage.org |
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Mon Mar 03, 2003 5:46 pm (21 years, 1 month ago) |
|
To add a banner, add a row to the table: leave the ID row blank, put the URL in banner_url, and put the image URL in banner_src. Oh, one thing I forgot: change the id column to auto increment.
Quote: | how would i make a link to go with each link? |
What do you mean? |
________________________________
|
|
|
|
Mad
Junior WebHelper
Joined: 20 Feb 2003
Posts: 18
Location: England
|
Posted:
Mon Mar 03, 2003 5:51 pm (21 years, 1 month ago) |
|
How would i make it so that banner one goes to link 1 and banner 2 to link 2 ? |
________________________________ www.celldamage.org |
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Mon Mar 03, 2003 5:57 pm (21 years, 1 month ago) |
|
The script I made already does that. Just change Code: | print('Banner URL: '.$row['banner_url'].' Banner SRC: '.$row['banner_src']); |
to Code: | print('<a href="'.$row['banner_url'].'"><img src="'.$row['banner_src'].'" border="0" /></a>'); |
|
________________________________
|
|
|
|
Mad
Junior WebHelper
Joined: 20 Feb 2003
Posts: 18
Location: England
|
Posted:
Mon Mar 03, 2003 6:52 pm (21 years, 1 month ago) |
|
Ahh ok, still stuck...i add the banner urls to the table in the MySQL database? can you give me an example? |
________________________________ www.celldamage.org |
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Mon Mar 03, 2003 7:47 pm (21 years, 1 month ago) |
|
Code: | INSERT INTO banners SET banner_url = 'http://www.site.com/', banner_src = 'http://www.site.com/image.gif' |
Have you managed to change the id column to auto increment? |
________________________________
|
|
|
|
Mad
Junior WebHelper
Joined: 20 Feb 2003
Posts: 18
Location: England
|
Posted:
Mon Mar 03, 2003 8:04 pm (21 years, 1 month ago) |
|
It came up with this error :
All parts of a PRIMARY KEY must be NOT NULL; If you need NULL in a key, use UNIQUE instead |
________________________________ www.celldamage.org |
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Mon Mar 03, 2003 8:05 pm (21 years, 1 month ago) |
|
OK, delete the banners table and recreate it with the following code:
Code: | CREATE TABLE banners (
id int(2) auto_increment,
banner_src varchar(255) NOT NULL,
banner_url varchar(255) NOT NULL
); |
|
________________________________
|
|
|
|
Darren
Team Member
Joined: 05 Feb 2002
Posts: 549
Location: London
|
Posted:
Sat Mar 08, 2003 7:42 pm (21 years, 1 month ago) |
|
Daniel wrote: | SELECT * FROM banners ORDER BY RAND() |
This doesn't appear to be very 'random'. I tried using it and it pulls out the same record much more often than any others. |
|
|
|
|
|