Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,194,792 members, 7,956,023 topics. Date: Sunday, 22 September 2024 at 09:40 PM |
Nairaland Forum / Science/Technology / Programming / Who Can Help Me Out With This Codes? (1537 Views)
Full Naijaloaded And Nairaland Codes / Download Free Project Source Codes And Materials From Projectbasket / What Softwares Are Used To Push Codes To A Live Website (2) (3) (4)
Who Can Help Me Out With This Codes? by Nobody: 7:24am On Feb 26, 2016 |
I created a code for like on my website, but when ever anybody likes a comment , the page is totally refresh and it takes the users to the top of the site, but does anyone have idea how nairaland did their likes e.g? www.nairaland.com/do_likepost?session=BBD453600902D4CBAE23FBAA58F25CEB193CFE59E48B17F480E3876BF71443BE&redirect=%2F2957092%2Foliseh-resigns-super-eagles-coach%2343259579&post=43259579 it doesn't reload a page, it act like a button, .. actually am writing with php language, 1 Like |
Re: Who Can Help Me Out With This Codes? by Liljeez(m): 8:31am On Feb 26, 2016 |
Send an e-mail to seun... |
Re: Who Can Help Me Out With This Codes? by Nobody: 8:36am On Feb 26, 2016 |
Liljeez:thanks, but I don't think he can help because nairaland is written in python |
Re: Who Can Help Me Out With This Codes? by Liljeez(m): 8:41am On Feb 26, 2016 |
Lexxyfund:yeah but he culd hav an idea |
Re: Who Can Help Me Out With This Codes? by Olumyco(m): 8:56am On Feb 26, 2016 |
I think u can use increment-storage style.... such dat for every click on d "likes" a code fires increasing the existing value and saving it in a database.... Eg ur like will have 0 has default but will not show... so when a user clicks on it, the number value will increase to 1 and 1 will b saved in a database and show .. Also if anoda person click it... it will increase to 2 which will change d saved number in d database to d current. ... As regards d issue of having d change instantly in d view without reloading d page... U will av to use these MVC frameworks like Angular, Backbone, React etc... Then whatever html code u av used 4 ur likes as regards gui ensure it does not av a default way of behaviour and if it does then prevent d default behaviour - u can use client side js 4 dat... .... Just my idea anyway.... 1 Like |
Re: Who Can Help Me Out With This Codes? by seunthomas: 9:01am On Feb 26, 2016 |
Lexxyfund:a. Use ajax. You send the event in the background and update the ui with response from the server. b. use an iframe. You load the like button in an iframe and when the user clicks it just update with the required image etc. 1 Like |
Re: Who Can Help Me Out With This Codes? by larisoft: 9:15am On Feb 26, 2016 |
you will have to use ajax to implement the feature in your html: <button onclick='increment_like(1, 3)'> Like </button> <!-- '1' being the id of the post and '3' being its current number of likes --> Now in your javascript: <script type='text/javascript'> // function increment_like(postId, currentLikes){ var variables = {id: postId, current_value: currentLikes}; $.post("http://ursite.com/increment_likes.php", variables , function(data, status){ alert('updated'); //this happens when the value has been changed }); } </script> IN your increment_likes.php <?php $id = $_POST['id']; $currentValue = intval($_POST['current_value']); $currentValue++; // add 1 to the no of likes //connect to database here (you know what i mean) mysqli_query($conn, "UPDATE likes_table SET no_of_likes = $currentValue WHERE id = $id" or die("something went wrong" // update the entry by changing the value of likes mysqli_close($conn) //close the connection ?> |
Re: Who Can Help Me Out With This Codes? by larisoft: 9:22am On Feb 26, 2016 |
larisoft:This will require jquery of course. If this is too complicated, then you can use html to go to the post of the page where the like button is located after a reload. http://mypage.php#postSection1. You will have to assign a different post section id to each post like this <section id='postSection1'> <!-- post here -- > <! -- post button here -- > </section Phew... I really hope any of this makes sense |
Re: Who Can Help Me Out With This Codes? by Nobody: 9:29am On Feb 26, 2016 |
thanks to everybody that contributed...
Liljeez
Olumyco
seunthomas
larisoft |
Re: Who Can Help Me Out With This Codes? by Liljeez(m): 10:29am On Feb 26, 2016 |
Lexxyfund:Though i didn't do anytin compared to those oda guys oh |
(1) (Reply)
Why Is Nairaland Homepage Looking Like This / How Do You Write Programs With Your Mobile Phone / Apparently Technical Interviews Arent Your Only Stumbling Block
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 20 |