I have a hit counter script that logs all its hits in one table, one row per
hit.
Currently, I have been counting the rows in PHP in order to get the value of
the last hit_id in the database like this:
$sql4 = "SELECT hits.hit_id from hits";
$result = mysql_query ($sql4, $connection)
or die("error #" . mysql_errno() . ": " . mysql_error());
$last = mysql_num_rows($result) - 1;
$go = mysql_data_seek($result, $last);
$row = mysql_fetch_object($result);
$pixels = number_format($row->hit_id);
Which is really expensive on my very tall hits table. I hit upon doing it in
MySQL, which is much, much faster:
$sql4 = "SELECT hits.hit_id
as pixels
from hits
WHERE hit_id=LAST_INSERT_ID();";
$result = mysql_query ($sql4, $connection)
or die("error #" . mysql_errno() . ": " . mysql_error());
$row = mysql_fetch_object($result);
$pixels = number_format($row->pixels);
It's staggering the difference in speed. But if I sit there and hit refresh
on the browser, I get wildly different values for $pixels. It jumps around
the actual number by +-10 or 12. The first method is precisely the same
every time (unless a hit is recorded in the interim). Am I doing something
wrong here? Can I not count on MySQL to know how many rows it has recorded
in a table? Any idea why that select statement would select a different row
each time?
Walter
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php