 <p>Use classes instead of IDs as propper markup there should be only 1 ID of a given name per page.</p> <p>HTML</p> <pre><code>loop 1 &lt;p&gt;- user review-&lt;/p&gt; &lt;a href="#" class="upvote" data-review="1"&gt;Up Vote&lt;/a&gt; loop 2 &lt;p&gt;- user review-&lt;/p&gt; &lt;a href="#" class="upvote" data-review="2"&gt;Up Vote&lt;/a&gt; etc. </code></pre> <p>JS</p> <pre><code>// jQuery / AJAX - separate file linked to `HTML` $('.upvote').on('click', function(e) { e.preventDefault(); var review_id = this.data('review'); $.ajax({ url : "search_query.php", type : "POST", dataType: "json", data : { reviewId : review_id }, success : function(data) { // do stuff } }); </code></pre> <p>PHP</p> <pre><code>&lt;?php $review_id = $database-&gt;escape_value(trim($_POST['reviewId'])); // Upvote Method $result = Data::upVoteReview($review_id, $_SESSION['user_id']); $output["result"] = $result; print(json_encode($output)); ?&gt; </code></pre>