My question is, how can we associate statistics to posts, for e.g. how is the like count tied to each Facebook post uniquely, or upvote and downvote stats linked to a question here on Stackoverflow. To elaborate further, say there is a question on stackoverflow and I click on the Upvote button, how can the system identify the question for which the upvote button has been clicked to send the stats to the backend DB? Since each question is dynamically generated by the users, how is it possible to give a unique ID to the button associated with each question?
Share
In the DB you would have an auto-incrementing ID field, when a question is generated and inserted into the db it is given an ID automatically, and in php + mysql you can get this id with the function mysql_insert_id().
Then when you output the html for the question, you add the id of the question into the html somehow.
It can be in a hidden field in a html form eg
<input type='hidden' name='questionid' value='52'></input>and then have it accessible in $_POST or $_GET in the phpor as part of the id or name of another element having an element with id or name of upvote52 and then you either extract it from the id/name via javascript before POSTing it to the php or you can just send it like that to the php and extract the ID from the rest of the string in the backend
or if its a anchor tag you can add it to the href as a paramater eg mysite.com/upvote.php?question=52 and then access it via $_GET in the php