4WebHelp
 FAQ  •  Search  •  User Groups  •  Forum Admins  •  Smilies List  •  Statistics  •  Rules   •  Login   •  Register
Toggle Navigation Menu

 Randomness
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic
Author Message
Mad
Junior WebHelper
Junior WebHelper


Joined: 20 Feb 2003
Posts: 18
Location: England

PostPosted: Sun Mar 02, 2003 5:33 pm (14 years, 7 months ago) Reply with QuoteBack to Top

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
OfflineView User's ProfileFind all posts by MadSend Personal MessageVisit Poster's WebsiteAOL Instant Messenger
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Sun Mar 02, 2003 5:52 pm (14 years, 7 months ago) Reply with QuoteBack to Top

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)?

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
Mad
Junior WebHelper
Junior WebHelper


Joined: 20 Feb 2003
Posts: 18
Location: England

PostPosted: Sun Mar 02, 2003 7:49 pm (14 years, 7 months ago) Reply with QuoteBack to Top

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
OfflineView User's ProfileFind all posts by MadSend Personal MessageVisit Poster's WebsiteAOL Instant Messenger
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Mon Mar 03, 2003 7:06 am (14 years, 7 months ago) Reply with QuoteBack to Top

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? Smile

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
Mad
Junior WebHelper
Junior WebHelper


Joined: 20 Feb 2003
Posts: 18
Location: England

PostPosted: Mon Mar 03, 2003 4:20 pm (14 years, 7 months ago) Reply with QuoteBack to Top

Would that select 3? If yes go ahead! Sorry, i don't have much PHP knowledge Confused

________________________________
www.celldamage.org
OfflineView User's ProfileFind all posts by MadSend Personal MessageVisit Poster's WebsiteAOL Instant Messenger
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Mon Mar 03, 2003 5:14 pm (14 years, 7 months ago) Reply with QuoteBack to Top

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>.

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
Mad
Junior WebHelper
Junior WebHelper


Joined: 20 Feb 2003
Posts: 18
Location: England

PostPosted: Mon Mar 03, 2003 5:38 pm (14 years, 7 months ago) Reply with QuoteBack to Top

where do i put in the banners?
how would i make a link to go with each link?
this is an affilates list btw Smile

________________________________
www.celldamage.org
OfflineView User's ProfileFind all posts by MadSend Personal MessageVisit Poster's WebsiteAOL Instant Messenger
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Mon Mar 03, 2003 5:46 pm (14 years, 7 months ago) Reply with QuoteBack to Top

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?

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
Mad
Junior WebHelper
Junior WebHelper


Joined: 20 Feb 2003
Posts: 18
Location: England

PostPosted: Mon Mar 03, 2003 5:51 pm (14 years, 7 months ago) Reply with QuoteBack to Top

How would i make it so that banner one goes to link 1 and banner 2 to link 2 ?

________________________________
www.celldamage.org
OfflineView User's ProfileFind all posts by MadSend Personal MessageVisit Poster's WebsiteAOL Instant Messenger
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Mon Mar 03, 2003 5:57 pm (14 years, 7 months ago) Reply with QuoteBack to Top

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>');

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
Mad
Junior WebHelper
Junior WebHelper


Joined: 20 Feb 2003
Posts: 18
Location: England

PostPosted: Mon Mar 03, 2003 6:52 pm (14 years, 7 months ago) Reply with QuoteBack to Top

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
OfflineView User's ProfileFind all posts by MadSend Personal MessageVisit Poster's WebsiteAOL Instant Messenger
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Mon Mar 03, 2003 7:47 pm (14 years, 7 months ago) Reply with QuoteBack to Top

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?

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
Mad
Junior WebHelper
Junior WebHelper


Joined: 20 Feb 2003
Posts: 18
Location: England

PostPosted: Mon Mar 03, 2003 8:04 pm (14 years, 7 months ago) Reply with QuoteBack to Top

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
OfflineView User's ProfileFind all posts by MadSend Personal MessageVisit Poster's WebsiteAOL Instant Messenger
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Mon Mar 03, 2003 8:05 pm (14 years, 7 months ago) Reply with QuoteBack to Top

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
);

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
Darren
Team Member



Joined: 05 Feb 2002
Posts: 549
Location: London

PostPosted: Sat Mar 08, 2003 7:42 pm (14 years, 7 months ago) Reply with QuoteBack to Top

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.
OfflineView User's ProfileFind all posts by DarrenSend Personal MessageVisit Poster's Website
Display posts from previous:      
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic


 Jump to:   


Go to page 1, 2  Next

You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot edit your posts in this forum.
You cannot delete your posts in this forum.
You cannot vote in polls in this forum.


Page generation time: 0.091099 seconds :: 17 queries executed :: All Times are GMT
Powered by phpBB 2.0 © 2001, 2002 phpBB Group :: Based on an FI Theme