How to scale PHP voting system for multiple posts?
I have a working PHP Ajax voting system that writes the likes from a blog post into a .txt file, and I want to scale it for multiple posts and record the likes from each of those.
I have tried to change the "onclick" value, but it seems that the script I am using limits me. I have done extensive research on Stackoverflow and other platforms, and tried many implementations. Please, can you assist with my below code, and point me to the right direction?
HTML
<span id="like"><a href="javascript:" name="vote"
value="0" onclick="getVote(this.value)">Like</a></span>
JAVASCRIPT
function getVote(int){
if(window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest()
}else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
}
xmlhttp.onreadystatechange=function({
if(this.readyState==4&&this.status==200{
document.getElementById("like").innerHTML=this.responseText
}
};
xmlhttp.open("GET","vote.php?vote="+int,true);
xmlhttp.send()
}
PHP
<?php
$vote=$_REQUEST['vote'];
$filename="votes.txt";
$content=file($filename);
$array=explode("-",$content[0]);
$yes=$array[0];
if($vote==0){
$yes=$yes+1;
}
$insertvote=$yes;
$fp=fopen($filename,"w");
fputs($fp,$insertvote);
fclose($fp);
?>