How to create a Facebook style "Like" system?
<p>I've been trying to find an example online of a Facebook style "Like" button but have not been able to find anything like this. What I would like to do is, place a button below an image which the user can press. Once pressed it will increment a value in the database for the image's record, and then reflect the addition on the page by adding + 1 to the existing amount. I can guess this will need PHP, SQL and jQuery to pull off. Problem is I have no idea where to begin. I've created already a PHP script to add to my Like's for a particular image by giving the image ID. I created already a jQuery post button which posts to the PHP and likes the image. The thing I'm stuck on is updating the page to reflect the like.</p>

<p>For starters, I think the code I made to do this so far is completely disgusting lol.</p>

<p>Here is all my code so far.
PHP to output the Likes count and Like button, plus code for addition. $info is the array for the result of my whole image files table:</p>

<pre><code>Echo "&lt;b&gt;Likes:&lt;/b&gt; ".$info['likes'] . "&lt;/span&gt;";
Echo '&lt;script src="http://code.jquery.com/jquery-latest.js"&gt;&lt;/script&gt;&lt;script     type="text/javascript"&gt;function test() {$.post("http://stormstorm.com/like.php?   id='.$info['fileid'].'")&lt;/script&gt;';
Echo '&lt;br /&gt;&lt;img onClick="test();" src="img/like.jpg"&gt;&lt;/p&gt;';
</code></pre>

<p>The PHP for the like incremented in like.php:</p>

<pre><code>$id = $_GET['id'];
mysql_query("UPDATE files SET likes=likes+1 WHERE fileid=".$id) or die(mysql_error());
</code></pre>

<p>The PHP for the liking works fine, I'm happy with that. But the thing to show the liking just sucks badly I think. Thing is I have a list.php which will print the contents of the database one after the other to print all the image listed. So it will print the same replica of the script over and over, typically hard coding the current image ID into the posting. I'm pretty new to this but feel this code sucks, plus it doesn't update the images section.</p>

<p>I was thinking to use Javascript to simply get the Likes element and ++ it but, then it hit me. My list will have over 100+ of these same elements. You can probably tell I might be approaching this the wrong way, and I hope someone can help me out with this.</p>
