Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,070 members, 7,818,197 topics. Date: Sunday, 05 May 2024 at 10:05 AM

Who Can Help Me Out With This Codes? - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Who Can Help Me Out With This Codes? (1517 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)

(1) (Reply) (Go Down)

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:
Send an e-mail to seun...
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:
thanks, but I don't think he can help because nairaland is written in python
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:
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,
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"wink or die("something went wrong"wink; // 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:

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"wink or die("something went wrong"wink; // update the entry by changing the value of likes
mysqli_close($conn) //close the connection
?>
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:
thanks to everybody that contributed... Liljeez



Olumyco



seunthomas



larisoft
Though i didn't do anytin compared to those oda guys oh

(1) (Reply)

We Need A Web/mobile App Developer Urgently / As A Full Stack Developer.. How Easy It Is To Get A Job? / Has The Tech Bubble Bust?

(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. 23
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.