![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Hello there. I have the very strange problem with the MySQL database [4.1.18]. I'm using it with PHP5. I have the table "pages_view" which is counting pages shows. Structure of the table looks like that: pvID - BIGINT AUTO_INCREMENT pvHash - VARCHAR(10) pvVisits - BIGINT pvID - index of the table pvHash - Hash of main_menu and sub_menu (for recognizing the page) pvVisits - main counter PHP Code looks like that: $hasz=$this->CreateMenuHash(); $r=mysql_query("SELECT pvID, pvVisits FROM pages_view WHERE pvHash='".$hasz."'"; $ile=mysql_count_rows($r); if ($ile==1) { $d=mysql_fetch_assoc($r); $odslon=$d["pvVisits"]; $odslon++; $r=mysql_query("UPDATE pages_view SET pvVisits='".$odslon."' WHERE pvID=".$d["pvID"]; echo "Viewed: ".$odslon; } else { $r=mysql_query("INSERT INTO pages_view (pvVisits, pvHash) VALUES ('1','".$hasz."')"); echo "Viewed: 1"; } It works perfectly well for the first show. It shows "Viewed: 1" and it's ok. When I press "Refresh" - troubles begins. It should show "Viewed: 2" but it doesn't. I got "Viewd: 3". When I press "Refresh" againa, I got "Viewed: 5". Nothing is pointing at the fact that the code is being executed twice. It is strange, that double counting is showing under IE and FireFox. Under Opera it works perfectly well, counting one by one. Maybe somebody can help? Thanks in above. PS: sorry for my english. Works as programmed. |
#3
| ||||
| ||||
|
|
Works as programmed. |
|
You have defined "pvID" as AUTO_INCREMENT and then in your code you increment it again with "$odslon++". |
|
$odslon=$d["pvVisits"]; |
|
$odslon++; $r=mysql_query("UPDATE pages_view SET pvVisits='".$odslon."' WHERE |
#4
| |||
| |||
|
|
User "Ronnie Chee" <cheer@[127.0.0.1]> wrote: Works as programmed. You do not understand single line from this code, is that right? You have defined "pvID" as AUTO_INCREMENT and then in your code you increment it again with "$odslon++". pvID is AUTO_INCREMENT I agree. But... $odslon=$d["pvVisits"]; Is that pvID? $odslon++; $r=mysql_query("UPDATE pages_view SET pvVisits='".$odslon."' WHERE Is that pvID? I can't figure it out, but don't treat me like a fool. And besides, where is explanation (if this what you wrote accept as truth) why it behave in different ways under different browsers. |
#5
| |||
| |||
|
|
My apologies. I read it quickly and posted a stupid and careless answer. You are right and I was very wrong. |
|
Did you try verifying the value of the field via the Query Analyzer before doing the refresh? |
|
Or echoing the relevant values before and after the increment step and before the update step? |
![]() |
| Thread Tools | |
| Display Modes | |
| |