Results 1 to 20 of 20

Thread: making counters

  1. #1

    Thread Starter
    Addicted Member TheGoldenShogun's Avatar
    Join Date
    Mar 2001
    Location
    VA/MD... anywhere around the beltway
    Posts
    236

    making counters

    I have a counter made right now but I'm wondering if it is the most effecient way of making one.

    Should I be making the counter table based or should I just keep incrementing from a text file? What is the best, most effecient way of doing it? I'm using a table now but that table will get so huge.

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    If you're just storing the number of times the page has been viewed, use a flat (.txt) file to save the number.

    Open it, get the value, increment it, write the new value, print the value to the page.

    I wouldn't use a MySQL database for it.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    man!! If I hadnt cleared off my server I would have a nice zip file that you could view to see how I wrote mine.

    I used a database that would make a new table every month so I could easily track the referer, the ip, browser, the page they were viewing, etc. etc. etc.

    I also had a really nice admin side to it too. I have a copy of it at my home, but I wont be there until August 8th.

    What a bummer!

    -Matt
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  4. #4

    Thread Starter
    Addicted Member TheGoldenShogun's Avatar
    Join Date
    Mar 2001
    Location
    VA/MD... anywhere around the beltway
    Posts
    236
    thats cool but you didn't run into any lag because your db got so big? I got counters made from tables and its pretty helpful, I track time/date, event they're viewing and can make nice reports from it but I'm just concerned that its going to get too massive in the future.

  5. #5
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    i never ran into a size problem. And I would find it more annoying to have to open a file read it, write to it and then close it.
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  6. #6
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    I thought he wanted a simple counter, not a monthly statistic thing. In which case I would still stand on my case that a file would be better. But okay...
    My evil laugh has a squeak in it.

    kristopherwilson.com

  7. #7
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    Yeah, I dont mind flat files and all but they are just a waste of time (or so I think). Why would you bother worrying about opening, grabing the text, exploding it to place the data into the correct variables, then displaying, all so you can then write it back so the most recent data is on top, and close up the file?

    It just seems like too much work for a counter, but maybe its not.
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  8. #8
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    PHP Code:
    $f fopen('file.txt''a+');
    $c fread($ffilesize($f));
    $c++;
    fwrite($f$c);
    fclose($f)

    echo 
    $c
    Seems alot easier to me than:

    PHP Code:
    $db mysql_connect("host""user""pass");
    mysql_select_db("main",$db);
    $c mysql_fetch_array(mysql_query("SELECT * FROM count LIMIT",$db));
    $c++;
    mysql_query("Update count SET num='$c' WHERE id='0'");

    echo 
    $c
    I guess it's just me, though.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  9. #9
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    im pretty sure you can shorten that to:

    PHP Code:
    $db mysql_connect("host""user""pass");
    mysql_select_db("main",$db);
    $query mysql_query("Update count SET num=num+1");

    // Read new value and display it after that 
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  10. #10
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    You shortened it by one line and also neglected two lines I had in there at are needed. I still think it's far easier to use a flat file. Don't go into overkill over something so simple.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  11. #11
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    Originally posted by The Hobo
    You shortened it by one line and also neglected two lines I had in there at are needed. I still think it's far easier to use a flat file. Don't go into overkill over something so simple.
    Just out of curiousity what two lines are needed?
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  12. #12
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    // Read new value and display it after that
    My evil laugh has a squeak in it.

    kristopherwilson.com

  13. #13
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    If we want to shorten things, we could get rid of a line here too:

    PHP Code:
    $f fopen('file.txt''a+');
    $c fread($ffilesize($f)) + 1;
    fwrite($f$c);
    fclose($f)

    echo 
    $c
    So compact it fits in your purse!
    My evil laugh has a squeak in it.

    kristopherwilson.com

  14. #14
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    lol, i know. I was just too lazy to write that line of code. If you want me to all it is, is this:

    PHP Code:
    echo mysql_result(mysql_query("select num from count order by id desc limit"),0,"num"); 
    -Matt
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  15. #15
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    It may only be one line longer, but mine is plenty columns shorter
    My evil laugh has a squeak in it.

    kristopherwilson.com

  16. #16
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    lol, you win.
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  17. #17
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    what do I win? free pass to hooters or the likes, eh?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  18. #18
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    Your prize is nothing of sentimental value but the knowledge you have exchanged over this thread along with the many others you have started, posted in, and solved.
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

  19. #19
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Oh. Not even a certificate or anything?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  20. #20
    Fanatic Member cpradio's Avatar
    Join Date
    Apr 2002
    Posts
    616
    If I had fireworks installed on my computer I would give you one, but im on a laptop in Texas 1300 miles away from my own computer ()
    http://cpradio.net/
    Administrator @ WDForums and a Moderator @ WebXpertz City Forums

Posting Permissions

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



Click Here to Expand Forum to Full Width