Results 1 to 4 of 4

Thread: Page Visit Counter

  1. #1
    Join Date
    Jan 2007
    Posts
    94
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question Page Visit Counter

    Soooo, I found this awesome script in one of the threads :

    PHP Code:
            <?php
    $cdata 
    file_get_contents("counter.txt");
    $ndata = ($cdata+1);
    $handle fopen("counter.txt","w+");
    fwrite($handle,$ndata);
    fclose($handle);
    echo 
    "\n<br>".$cdata." visits";
    ?>
    But, here's my issue and i'm hoping someone can help me...
    All my blogs go to one page and I pull from a SQL table and display the data for the particular blog selected... Example:

    /viewblogdetails.php?blogid=205

    ok, so I put the above script on that page and it of course increments every time the page is pulled up - regardless of the particular blog. I want to make a counter that counts only the views for a particular blog. Is that possible? Can I modify this code to make that?

    Any help would be appreciated! Thanks!

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    If you're using SQL, then wy not just use that to store the count?
    Anyway, sure. Just find some way to create a specific text file per SQL item created.
    For example, if you have $table set as the table you're searching in the database, then you could use $table.'counter.txt', which would be a specific file to the particular table used.
    Or, instead of $table, use whatever data IS specific, such as the part of the SQL command with WHERE ____ = 'THIS'.
    So, find the specific info, then use that in addition to the filename.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Jan 2007
    Posts
    94
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    I don't know why I didn't think of doing via SQL... but that's what I ended up doing, thanks!

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Best option. Glad it worked out.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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
  •