> $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?

>From http://www.mysql.com/doc/M/i/Miscellaneous_functions.html:

The last ID that was generated is maintained in the server on a
per-connection basis.

Since LAST_INSERT_ID() works on a per-connection basis, and since you are
most likely using persistent connections, each reload of your web browser
returns a different instance of the http server and therefore a different
persistent connection. The best way to do it would probably be to update the
last id in the table right after inserting the row (update othertable set
row = last_insert_id() where yadda yadda yadda).


---------------------------------------------------------------------
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

Reply via email to