GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 11-Feb-2007, 09:43
Richardknox Richardknox is offline
Junior Member
 
Join Date: Nov 2006
Location: Michigan
Posts: 83
Richardknox is on a distinguished road
Question

Need help tracking how many times viewed


I am in need of some assistance. I run a website that maintains a list of Webcams. I am trying to track how many times each webcam is viewed, but only incrementing the count by 1 per visitor per day, regardless on how many times they select that link/webcam.

(ex: Joe views the cam, and it increments by 1. Joe clicks the link multiple times, but it only updates once. The rest of the clicks don't increase the count.)

I have been experimenting with another script that I have, but I am unable to get it to work. Any help will be greatly appreceated.

PHP Code:

<?
// viewed.php
include "db_connection.php";
?>
<?
//Gets the id number assosiated with the webcam
$id=$_GET['id'];
// Connects to the SQL database
$dblink = mysql_connect($dbhostname,$dbusername, $dbpassword) OR DIE ("Unable to connect to database! Please try again later.");
mysql_select_db($dbname, $dblink);

// query the webcam table for the selected webcams information.
$query = "SELECT * FROM wcdatabase WHERE id = ($id) LIMIT 0, 30 ";

$result = mysql_query($query,$dblink);

$row = mysql_fetch_assoc($result);


// Obtain user IP address
$searchIP = mysql_escape_string( $_SERVER['REMOTE_ADDR'] );

// Query viewed table

$sql = "SELECT `camid` FROM `wcviewed_ip` WHERE `ip_bin`=INET_ATON('$searchIP')";

if( $resource=@mysql_unbuffered_query($sql, $dblink) )
{
    $sql = false;
    
    if( $row=@mysql_fetch_row($resource) )
    {
    
    echo ($row[0]. ' / '.$id);
        if( $row[0] != $id )
        {
            
            // insert the new visitor into the viewed table (IP Address, Cam viewed, todays date)
        
        $sql =    "INSERT INTO
                    `wcviewed_ip`
                    ( `ip_bin`, `camid`, `lastdate` )
                   VALUES
                    ( INET_ATON('$searchIP'), '$id', CURDATE() )";
                    
                    // Increment the number of time the Webcams has been viewed by 1.
                    $row["viewed"]++;
        
                    $viewed = $row["viewed"];
                    
                    // UPDATE the webcam table for the webcam viewed.
                    $query = "UPDATE wcdatabase SET viewed = ($viewed) where id = ($id)";

                    $result = mysql_query($query, $dblink); 
            
            
                        
        }
    }
    else
    {
        // Update viewed table for existing user.
           echo (update);
            $sql =    "UPDATE
                      `wcviewed_ip`
                            SET
                       `lastdate`=CURDATE()
                      
                 WHERE
                      `ip_bin`=INET_ATON('$searchIP')";
                      
                      // Increment the number of time the Webcams has been viewed by 1.
                    $row["viewed"]++;
        
                    $viewed = $row["viewed"];
                    
                    // UPDATE the webcam table for the webcam viewed.
                    $query = "UPDATE wcdatabase SET viewed = ($viewed) where id = ($id)";

                    $result = mysql_query($query, $dblink); 
                    
    }
    
    if( $sql )
    {
        @mysql_unbuffered_query( $sql, $dblink )
            or die( mysql_errno($dblink) . ' - ' . mysql_error($dblink) );
    }
}
else
{
    trigger_error( "Cannot add/update visitor data to `wcviewed_ip`; SQL query error; searchIP=$searchIP", E_USER_NOTICE );
} 
?>


I am certain that there are newbie mistakes within this script, so I will appoligise upfront.

Thanks for the help.

Richard
 
 

Recent GIDBlogNot selected for officer school by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
times table program J-a-Y C++ Forum 4 14-Dec-2005 14:18
Suggest design and layout for C/CPP/JAVA bbcodes admin GIDForums™ 6 09-Sep-2005 21:56
Google Adsense introduces tracking by URL Div Advertising & Affiliates Forum 1 14-Dec-2004 07:14
Mvtracker.com - usefull tracking mvtracker Advertising & Affiliates Forum 1 31-Aug-2003 06:18
approx. down-load times darrin Web Design Forum 3 22-Aug-2002 15:55

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 22:01.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.