Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It looks like you have the general idea down, just a crude implementation of it.</p> <p>You may want to designate the counter element for each image and update the inner content after the button is pressed...</p> <pre><code>&lt;img src="xxx.jpg"&gt; &lt;p&gt; &lt;a href="javascript:test({image_id});"&gt;Like&lt;/a&gt; &lt;span id="{image_id}_count"&gt;150&lt;/span&gt; &lt;/p&gt; </code></pre> <p>where the {image_id} is obviously unique to each image. Pass that to test({image_id}) and then update the html of the count total on success...</p> <pre><code>function test(id) { $.ajax({ url: 'http://stormstorm.com/like.php', method: 'get', data: {id: id}, dataType: json, success: function(data) { $('#' + id + '_count').html(data.total); } }); } </code></pre> <p>in your php you would do exactly what you did except return a json encoded array back to the js for update...</p> <pre><code>$id = mysql_real_escape_string($_GET['id']); mysql_query("UPDATE files SET likes=likes+1 WHERE fileid=".$id); if(mysql_affected_rows() &gt; 0) { $sql = mysql_fetch_assoc(mysql_query("SELECT `likes` FROM `files` WHERE `fileid` = ".$id)); echo json_encode(array('total' =&gt; $sql[0]['likes'])); } </code></pre> <p>Keep in mind this is a VERY POOR implementation of this. The real system should definitely be one that does not allow people to just repeatedly click the button over and over again to increment something for the hell of it. According to your needs, of course, you should limit it by login and even record user information relative to the file they're liking and not just increment a number in the database. So you would have a relational table that stores information for each like. That way you can query the database to make sure a user has not already liked the file before incrementing the number.</p> <p>Hope that makes sense.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload