...

View Full Version : Script to Random Pull a link each reload from a Database of 100 links



remusssslim
03-08-2008, 06:41 PM
I have a database of 100 links, how can I make a random page load each time a user comes into the page.

Is it also possible to allow a maximum number of page loads for each link so that it will not exceed it within a set period like 24 hours?

For example:

I have

Link 1
Link 2
Link 3
Link 4

Each time it will load a random link and what happens is that for Link 1, it will only load up to 100 times and then it will never load LInk 1 again for the day.

rafiki
03-08-2008, 06:42 PM
Mysql database? do you have PHP?

remusssslim
03-08-2008, 06:45 PM
Mysql database? do you have PHP?

Hi

Yes I do. Is it a difficult process? I would like to put it in a 200x200 iFrame by the side of my website.

harbingerOTV
03-08-2008, 06:46 PM
We'll need to know the serverside language your using (php, asp, .net, etc) to answer the first.

For the second, I'm sure it is but the script, once again, will depend on the language your using.

remusssslim
03-08-2008, 07:23 PM
We'll need to know the serverside language your using (php, asp, .net, etc) to answer the first.

For the second, I'm sure it is but the script, once again, will depend on the language your using.

THat would be PHP. :)

rafiki
03-08-2008, 09:40 PM
ill get a mod to pop it over to the php forum and give you a reply there.

rafiki
03-08-2008, 09:48 PM
include 'dbconnect.php';

$q = mysql_query(SELECT * FROM `links` ORDERBY RAND() LIMIT 1) or die(mysql_error());
$res = mysql_result($q) or die(mysql_error());
echo "<a href=\"$res[linktarget]\" > $res[linktext] </a>";


assuming you just want one link per load?

remusssslim
03-09-2008, 06:49 AM
include 'dbconnect.php';

$q = mysql_query(SELECT * FROM `links` ORDERBY RAND() LIMIT 1) or die(mysql_error());
$res = mysql_result($q) or die(mysql_error());
echo "<a href=\"$res[linktarget]\" > $res[linktext] </a>";


assuming you just want one link per load?

Hi

Yes. but how can I enter the links to be loaded? Can it be stopped once the link is loaded 10 times?

rafiki
03-09-2008, 11:21 AM
include 'dbconnect.php';

$q = mysql_query(SELECT * FROM `links` WHERE `shown` < 10 ORDERBY RAND() LIMIT 1) or die(mysql_error());
$res = mysql_result($q) or die(mysql_error());
echo "<a href=\"$res[linktarget]\" > $res[linktext] </a>";
$q = mysql_query("UPDATE `links` set `shown` = {$res['shown']++} where `linktarget` = {$res['linktarget']}");
mysql_result($q) or die(mysql_error());

effpeetee
03-09-2008, 09:48 PM
My site -
www.exitfegs.co.uk
uses random picture selection at start up. It is done using Javascript.
If you find it useful, I can post the Javascript code.:D

Frank

sage45
03-09-2008, 10:10 PM
Moving to PHP

-saige-

Inigoesdr
03-09-2008, 10:48 PM
$q = mysql_query(SELECT * FROM `links` WHERE `shown` < 10 ORDERBY RAND() LIMIT 1) or die(mysql_error());

You need quotes around your query, and a space for ORDER BY:

$q = mysql_query('SELECT * FROM `links` WHERE `shown` < 10 ORDER BY RAND() LIMIT 1') or die(mysql_error());
Also, to answer the OP's question: In order to make sure it is only shown a certain number of times per day you'll have to either reset the "shown" field for all links, once a day, OR store the times each banner is shown in a separate table.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum