Copy link to clipboard
Copied
I know, it's an often asked question, but I think I have a different requirement to most samples that I have found out there on the net, so I thought I'd ask for some advice here.
I am looking to create a page counter that is stored within the MySQL database as part of the record that has been viewed. and I am not quite sure as to how to go about this.
I know I need a column in my table that stores the amount of times a record has been viewed, but I can't figure out how I should firstly trigger how a record has been viewed, and then I can't figure out how to increment it by one each time it has been viewed.
I don't really want to have a separate table for the counter as I intend to use the info elsewhere where it is pulling the whole record info onto a page.
Any thoughts/tuts/examples/samples are welcome.
Many thanks.
Yes, that is correct.
Copy link to clipboard
Copied
![]()
Doesn't anybody have any idea of how I might attack this?
How do I submit to the database that a record has been viewed and increment it by 1?
If this was a form, I am sure I could do it as I am able to insert and update records within a DB, but as there is no form involved in this, I have no idea how to attack it and make it count from 0 to 1 to 2 and so on...
Thanks
Copy link to clipboard
Copied
If someone is viewing a record then there would be a related SELECT statement. Right after the SELECT statement, just issue an UPDATE statement against the same record that increments the field by 1.
Copy link to clipboard
Copied
OK. I understand the concept behind that, and I can see it would work for me.
How do I trigger the update statement though? I'm only aware of being able to update a record by clicking a form button.
Copy link to clipboard
Copied
Just found this on tinternet...
mysql_query("UPDATE counter SET counter = counter + 1");
I assume 'counter' is the name of the column with the DB table, and that as soon as the page is loaded it will automatically update the appropriate record. Is that right?
Thanks.
Copy link to clipboard
Copied
Yes, that is correct.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more