|
-
Oct 3rd, 2002, 10:13 PM
#1
Thread Starter
Fanatic Member
URGENT: What is wrong with my counter?>??!??
I have a counter which keeps track of how many times a page has been visited today and how much total. For some reason, my counters keep reseting... im pretty sure my code is good, but maybe its not? Can anyone please see if my code has a problem??
PHP Code:
function CountPage ($pg) {
global $db;
$db->query ("SELECT * FROM counters WHERE page='$pg'");
if ($db->fetchRow ()) {
// Update the count
$curtodaycount = intval($db->record["todaycount"]);
$curtotalcount = intval($db->record["totalcount"]);
// change the date here
$todaydate = $db->record["todaydate"];
$curtotalcount ++;
if ($todaydate == date("Y-m-d")) {
$curtodaycount ++;
}
else {
$todaydate = date("Y-m-d");
$curtodaycount = 0;
// Reset all counters to 0
$db->query("UPDATE counters SET todaydate='$todaydate', todaycount='0'");
}
// Now update the count
$db->query("UPDATE counters SET todaydate='$todaydate', todaycount='$curtodaycount', totalcount='$curtotalcount' WHERE page='$pg'");
}
else {
// Create a new record
$curtodaycount = 1;
$curtotalcount = 1;
$todaydate = date("Y-m-d");
// Insert
$db->query("INSERT INTO counters (page,todaydate,todaycount,totalcount) VALUES('$pg','$todaydate','$curtodaycount','$curtotalcount')");
}
$db->showErrors ();
}
I have no idea whats going on...
-
Oct 3rd, 2002, 10:32 PM
#2
Stuck in the 80s
did you debug all the IFs to make sure it was returning true where it should have and all that jazz?
It's probably some really small error, but those are always the hardest to find.
-
Oct 3rd, 2002, 10:33 PM
#3
Thread Starter
Fanatic Member
It worked fine before, it suddenly stopped working (i dont kno what i did wrong)
-
Oct 3rd, 2002, 10:35 PM
#4
Shouldn't this
// Reset all counters to 0
$db->query("UPDATE counters SET todaydate='$todaydate', todaycount='0'");
Include a WHERE clause for the Page being referenced?
-
Oct 3rd, 2002, 10:42 PM
#5
Thread Starter
Fanatic Member
I only have two if/else's one of them (I Know it works), is the $db->fetchRow() which just updates the db->records[] array on the record and the next one:
PHP Code:
if ($todaydate == date("Y-m-d")) {
This always worked and infact to be sure i made a simple script to test it and it worked!
Aaron Young: I didnt use WHERE because I want it to reset ALL the counters to 0 at the end of the day.
I have a table like this:
Code:
Page: Today: Total:
----------------------------------------------
Home 91 2523
Contact Us 23 126
Search 32 632
...
And for some reason at around 6pm, the counters mysteriously reset... i dont know whats going on, but my code looks fine right? I mean it worked the other days...
-
Oct 4th, 2002, 05:49 PM
#6
Frenzied Member
if it keeps reseting
if ($todaydate == date("Y-m-d")) { then apparently this is never true
$curtodaycount ++;
}
else {
$todaydate = date("Y-m-d");
$curtodaycount = 0;
// Reset all counters to 0
$db->query("UPDATE counters SET todaydate='$todaydate', todaycount='0'");
}
-
Oct 4th, 2002, 05:59 PM
#7
Thread Starter
Fanatic Member
Let me rephrase that, and i have some reason to think that this is server related (maybe either the server or mysql have the wrong time)...
Its supposed to reset at MIDNIGHT, any other time, its supposed to increment. But for some weird reason it resets at some awkward times! I verified that my code isnt the problem, but maybe the mysql or the unix machine! I am now contacting the admin and trying to get things to work out.
Thanks everyone for your quick responses! I really appreciate it!
-
Oct 4th, 2002, 06:17 PM
#8
Stuck in the 80s
Originally posted by MoMad
Let me rephrase that, and i have some reason to think that this is server related (maybe either the server or mysql have the wrong time)...
Its supposed to reset at MIDNIGHT, any other time, its supposed to increment. But for some weird reason it resets at some awkward times! I verified that my code isnt the problem, but maybe the mysql or the unix machine! I am now contacting the admin and trying to get things to work out.
Thanks everyone for your quick responses! I really appreciate it!
Yeah, I'm sure.
-
Oct 5th, 2002, 01:28 PM
#9
Frenzied Member
-
Oct 5th, 2002, 06:28 PM
#10
-
Oct 5th, 2002, 06:41 PM
#11
Thread Starter
Fanatic Member
Its FIXED!! PHP returns in GMT time so I just made a custom function that will convert date() to date() - 7hours
-
Oct 5th, 2002, 10:45 PM
#12
Stuck in the 80s
Originally posted by MoMad
Its FIXED!! PHP returns in GMT time so I just made a custom function that will convert date() to date() - 7hours
It took you this long to fix it?
The first thing I would have done would be to check the server's timezone just be echoing the date...
-
Oct 6th, 2002, 03:38 AM
#13
Thread Starter
Fanatic Member
why didnt i think of that?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|