Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New to the CF scene
    Join Date
    Mar 2008
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Script to Random Pull a link each reload from a Database of 100 links

    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.

  • #2
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,043
    Thanks
    19
    Thanked 42 Times in 42 Posts
    Mysql database? do you have PHP?

  • Users who have thanked rafiki for this post:

    remusssslim (03-08-2008)

  • #3
    New to the CF scene
    Join Date
    Mar 2008
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by rafiki View Post
    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.

  • #4
    Senior Coder
    Join Date
    Jan 2005
    Location
    Memphis, TN
    Posts
    1,785
    Thanks
    8
    Thanked 131 Times in 129 Posts
    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.
    Stop making things so hard on yourself.
    i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis

  • #5
    New to the CF scene
    Join Date
    Mar 2008
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by harbingerOTV View Post
    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.

  • #6
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,043
    Thanks
    19
    Thanked 42 Times in 42 Posts
    ill get a mod to pop it over to the php forum and give you a reply there.

  • #7
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,043
    Thanks
    19
    Thanked 42 Times in 42 Posts
    PHP Code:
    include 'dbconnect.php';

    $q mysql_query(SELECT FROM `linksORDERBY 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?

  • #8
    New to the CF scene
    Join Date
    Mar 2008
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by rafiki View Post
    PHP Code:
    include 'dbconnect.php';

    $q mysql_query(SELECT FROM `linksORDERBY 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?

  • #9
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,043
    Thanks
    19
    Thanked 42 Times in 42 Posts
    PHP Code:
    include 'dbconnect.php';

    $q mysql_query(SELECT FROM `linksWHERE `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()); 

  • #10
    Senior Coder effpeetee's Avatar
    Join Date
    Feb 2007
    Location
    Clapham Junction - London SW
    Posts
    4,885
    Thanks
    228
    Thanked 204 Times in 203 Posts
    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.

    Frank
    * Sources (updated: 21.11.2012.
    Using Windows 8 Professional. 64bit with HP Photosmart 5510 printer Very useful site here.

  • #11
    Super Moderator sage45's Avatar
    Join Date
    May 2002
    Posts
    1,060
    Thanks
    0
    Thanked 13 Times in 13 Posts
    Moving to PHP

    -saige-
    HTML & CSS Forum Moderator

    "If you don't know what you think you know, then what do you know."
    R.I.P. Derrick Thomas #58
    1/1/1967 - 2/8/2000

  • #12
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Quote Originally Posted by rafiki View Post
    PHP Code:
    $q mysql_query(SELECT FROM `linksWHERE `shown` < 10 ORDERBY RAND() LIMIT 1) or die(mysql_error()); 
    You need quotes around your query, and a space for ORDER BY:
    PHP Code:
    $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.
    Last edited by Inigoesdr; 03-09-2008 at 09:53 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •