Hello, I have this PHP code: $sql = "UPDATE video SET viewnumber=viewnumber+1, viewtime='" .date('Y-m-d H:i:s'). "' WHERE VID = '" .$VID. "' LIMIT 1"; $conn->execute($sql); Currently, when the page is visited the view count gets added +1 and so on. I want that view count to be as little as possible. Let's say 4 visits = 1 view count. Let's say 4 people visited http://blahblah.com/videoblablah.html = the counter will only count 1view on the video. Is it okay to put it like this: viewnumber=viewnumber+0.25 so the count of 1 is divided into 4? so 4 views will be 1view only? or just divide total view counts by 4?
If the field is a real number, you can do it that way. If it's an integer the count will never increase. If this is a MySQL database, use phpMyAdmin to go to it, look at the structure of the table 'video' and make sure that 'viewnumber' is a field that can take a fraction. Then make sure that the rest of the code doesn't blow up. (Always take a full backup of the dsatabase before playing with it.)
Hi Rukbat, This is a MySQL DB and I have this: viewnumber bigint(10) on table video.. Is this okay to put. +0.25 ?
You can, but since 0.25 isn't an integer, you'll be adding 0. Change the field to number/real (after you back up at least that table, in case you lose data when you make the change).
what do you mean real number? Like this: $sql = "UPDATE video SET viewnumber=viewnumber-1, viewtime='" .date('Y-m-d H:i:s'). "' WHERE VID = '" .$VID. "' LIMIT 1"; $conn->execute($sql); sorry im really confused.
Just divide by 4. It's much easier. The other suggestion was to change the Field to a Float/Real in the database structure.
um, would depend on the code you use to extract data. That is, do it when you show the number of views and leave the DB alone. So it would be $view_cnt = $viewcount / 4;
Hi, will that add +0.25? I think you meant: UPDATE video SET viewnumber=viewnumber+1/4 right? or just directly UPDATE video SET viewnumber=viewnumber/4 ? Here is the original code: $sql = "UPDATE video SET viewnumber=viewnumber+1, viewtime='" .date('Y-m-d H:i:s'). "' WHERE VID = '" .$VID. "' LIMIT 1"; $conn->execute($sql);
No, its not what I meant. Add 1 for each view. Go find the code where you view the count and change that so its divided by 4. If you want to add .25, you will have to go into phpmyadmin and change the viewnumber field to a Real or Float. Then you can modify the insertion code but odds are if you do that, you will have to find the code to display the viewcount and modify it to round the result. So just modify the code used to display the result.
I think I will have to go with your solution shallowink. Below is the code: Would you mind helping create that +1 viewcount and then divide by 4 to be in accordance to your suggestion?
The type of the field in the database that holds the data. Change that from the int field it is now to a number field of type Real. The problem with adding 1 and dividing by 4 is that your first view will show 0.25 views. You could write code to round the view up to the next lowest integer, so 0, 0.25, 0.5 and 0.75 would all show 0, 1, 1.25, 1.5 and 1.75 would all show 1, etc. But it's a lot easier just changing the database field to a real number, then displaying the integer of that number [use intval()].
if you are going to be adding +0.25 to the view count, you will need to change the structure type in the database, from an integer to a float, otherwise you view count won't change, because when you add the 0.25 it will be rounded down to 0. as for your reasons for reducing the view count, i am truly confused by it.
It works! Except for the fact that it is showing a decimal on the view count. Views: 173.5 How do you make that only appear wholenumber and no decimal? I only want to alter how the count per view is adding up, but update the view count on frontend when it is a wholenumber and note decimal?
You have 2 options, ceil($number); #Rounds off to highest floor($number); #Rounds off to lowest PHP: Glen
I am suprised no one just added a new column to the field and added +1, when the value reached = to the value of the split view counter you would then reset to 0 and +1 to the actual view counter.