SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Run every x amount of time

    I have to display a block 30 percent of the time. So for example: for every 10 people that visit my page, I want to display this block only 3 times.

    Anyone have any thoughts on how to do this? I can control if my block get's display via PHP but how can I make it only perform 30 percent of the time.

  2. #2
    Pedantic Semantic blain's Avatar
    Join Date
    Mar 2006
    Location
    Yorkshire, UK
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It depends, do you want to show it once for every three visits, or give each visit a 30% chance of seeing it?
    Technology is dominated by two types of people:
    those who understand what they do not manage,
    and those who manage what they do not understand.

  3. #3
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by blain View Post
    It depends, do you want to show it once for every three visits, or give each visit a 30% chance of seeing it?
    Once every 3 visits.

  4. #4
    SitePoint Enthusiast jakub_polak's Avatar
    Join Date
    Jan 2012
    Location
    Slovakia
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1.) create a database table called "visit_counter" with fields id_visit, visit_count; visit_count starts at 0

    2.) when a visitor comes to the page with the "block" add 1 to the visit_count field in "visit_counter" table, so after first visit there is number 1, after second visit there is number 2 etc.

    3.) each visit to the page, get the value of visit_count from database and perform:


    PHP Code:
    if ($visit_count == 0){
    // display block

    Thats it.

  5. #5
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thanks!

    That is the same way I'm thinking. I guess there is no way of doing it other than storing the count in the database or a file.


Bookmarks

Posting Permissions

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