Regret, that: Php mysql jquery file download counter
Windows 7 ultimate .iso file download | Screen recorder for pc free download without watermark |
Download game with xbox game pass pc | Judas priest download free best songs.mp3 |
Imo old vertion free download | Download array to txt file |
Latest flash player download windows 10 | Facebook gameroom download for windows 10 64 bit |
Facebook Style Like Unlike using PHP jQuery
This tutorial has an example code for doing like unlike which we have seen in many websites like Facebook. We are using jQuery AJAX to call PHP for updating likes count in the database. We are using the IP address of the visitors to compute the like or unlike status.
View DemoDownload
Database Results to Like Unlike
This code is for listing database results with like unlike icons based on the likes status.
<table class="demo-table"> <tbody> <tr> <th><strong>Tutorials</strong></th> </tr> <?php if(!empty($result)) { $ip_address = $_SERVER['REMOTE_ADDR']; foreach ($result as $tutorial) { ?> <tr> <td valign="top"> <div class="feed_title"><?php echo $tutorial["title"]; ?></div> <div id="tutorial-<?php echo $tutorial["id"]; ?>"> <input type="hidden" id="likes-<?php echo $tutorial["id"]; ?>" value="<?php echo $tutorial["likes"]; ?>"> <?php $query ="SELECT * FROM ipaddress_likes_map WHERE tutorial_id = '" . $tutorial["id"] . "' and ip_address = '" . $ip_address . "'"; $count = $db_handle->numRows($query); $str_like = "like"; if(!empty($count)) { $str_like = "unlike"; } ?> <div class="btn-likes"><input type="button" title="<?php echo ucwords($str_like); ?>" class="<?php echo $str_like; ?>" onClick="addLikes(<?php echo $tutorial["id"]; ?>,'<?php echo $str_like; ?>')" /></div> <div class="label-likes"><?php if(!empty($tutorial["likes"])) { echo $tutorial["likes"] . " Like(s)"; } ?></div> </div> <div class="desc"><?php echo $tutorial["description"]; ?></div> </td> </tr> <?php } } ?> </tbody> </table>jQuery Call for Like Unlike Update
This function will be called on the click event of like, unlike thumb icons. This will execute PHP code via AJAX and update database based on the requested action. On receiving successful AJAX response, this function will update the likes status and count. The script is,
PHP MySQL Like Unlike Update Query Handling
This PHP code receives action from the AJAX call and performs database likes update based on this action. The code is,
<?php if(!empty($_POST["id"])) { require_once("gwd.es"); $db_handle = new DBController(); switch($_POST["action"]){ case "like": $query = "INSERT INTO ipaddress_likes_map (ip_address,tutorial_id) VALUES ('" . $_SERVER['REMOTE_ADDR'] . "','" . $_POST["id"] . "')"; $result = $db_handle->insertQuery($query); if(!empty($result)) { $query ="UPDATE tutorial SET likes = likes + 1 WHERE id='" . $_POST["id"] . "'"; $result = $db_handle->updateQuery($query); } break; case "unlike": $query = "DELETE FROM ipaddress_likes_map WHERE ip_address = '" . $_SERVER['REMOTE_ADDR'] . "' and tutorial_id = '" . $_POST["id"] . "'"; $result = $db_handle->deleteQuery($query); if(!empty($result)) { $query ="UPDATE tutorial SET likes = likes - 1 WHERE id='" . $_POST["id"] . "' and likes > 0"; $result = $db_handle->updateQuery($query); } break; } } ?>View DemoDownload
Back to Top
0 thoughts to “Php mysql jquery file download counter”