Reputation: 2363
I have a table that displays a list of companies. Each time a company's record is displayed, I need to save the view in a MySQL database. I'm using PHP's PDO to connect to MySQL and was wondering how to update a table column each time the record is displayed.
For example, company "a"'s record has been displayed 10 times. After two users go to the page, the "views" column in the database for that company's record needs to be updated to 12.
Can someone give me an example as to how to accomplish this?
Upvotes: 1
Views: 115
Reputation: 6632
You can just call an UPDATE
query and increment the value of the views column by one.
Or, you can create a procedure to do it at once. For example: MySQL UPDATE and SELECT in one pass
Upvotes: 1