|
Posted by Dave on 09/04/05 15:50
On Sun, 04 Sep 2005 12:17:17 +0000, toedipper wrote:
> Hello,
>
> PHP and MYSql
>
> I have the code below which logs a visitor to my site via logging the
> session id and other details in a table. I only want to count a visit
> once so I have a check to see if the session id is in the table already
> then don't log it. I don't want an entry in the event of a surfer
> hitting refresh on the browser or revisitng the page during a session.
>
> However, not only is it logging the first initial visit during the
> session but it is also logging the second. It does not log the third
> visit on.
>
<snip code>
> $sqlchecksession = "SELECT sessionid from visitors where sessionid =
> '$sessionid'";
> $result = @mysql_query($sqlchecksession, $local) or die(mysql_error());
> $thenum = mysql_num_rows($result);
> if ($thenum <=1 ) {
You are checking if 1 or fewer rows exists. The comparison should be
less than, not less than or equal to.
Why not just create a unique index on the sessionid column? You would
then not need to bother checking for existence at all - MySQL will
simply refuse to insert a row if one with the same sessionid
already exists.
<snip>
--
Dave <dave@REMOVEbundook.com>
(Remove REMOVE for email address)
[Back to original message]
|