Hide comment after deleting - php

I have tride to add function hide after deleting the comment. but it hide all comments. but i need to hide just deleted comment. there is my js.
$('.delete_p').click(function(){
var del_id = $(this).attr('id_p');
$.ajax({
type: 'POST',
url: 'delete_post.php',
data:'delete_id='+del_id,
success: function(data){
$('#status .holder'+del_id).fadeOut();
}
});
});
$( ".delete_p" ).click(function() {
$( "#status .holder").hide("slow");
});
i have tride to add thisbut it doesn't helped.
$( "#status .holder", $(this)).hide( "slow" );
here is html. it is too long. there is just used for comment:
<div id="status">
<div class='holder' id_p='<?php echo $post_id; ?>'>
<div class='holder_half'>
<?php
$default_s_pic = "href=/default_picture.png";
echo "<div id='picture'><a href='/$poster_name'>";
if($adder_pic === ""){
echo '<img src="', $default_s_pic, '" alt="', $poster_f_name,'\'s Profile image">';
}else{
echo '<img src="', $adder_pic, '" alt="', $poster_f_name,'\'s Profile image">';
}
echo "
</a>
</div>
<div class='ten'>
<div id='statusname'><a href='/$poster_name'>$poster_f_name</a></div>
<div class='date_time'>$data</div>
<span class='span' data-ft='{"tn":"K"}'>
";
if($posted_place === $deleter || $poster_name === $deleter){
echo "
<button class='delete_p' id_p='". $post_id ."'>x</button>
";
?><script src="delete_post.js"></script>
</div>
</div>
</div>
</div>

Change This code:
<div class='holder' id_p='<?php echo $post_id; ?>'>
to this:
<div class='holder<?php echo $post_id; ?>' id_p='<?php echo $post_id; ?>'>

Related

AJAX pagination not working properly after new entry

I am having a main page "landing.php", here in a div i am calling another page using ajax function "fetch_pages.php". In fetch_pages.php, i am loading data from db as 5 records at a time, when the user reaches the end of page then next 5 records are displayed. Thats working perfectly.
But in landing.php, when i enter a new record and reload the div, then the div content becomes blank, it doesn't show the latest content, after refreshing the full page manually then its again shows all the records. Can't understand whats wrong, kindly help.
landing.php page
<div class="mainsection">
<div>
<div class="pull-left postimage"><?php echo "<img src=profile_pic/".$ProfilePic ." />"; ?></div>
<div class="pull-left posttext">
<div class="postname"><?php echo $Name; ?></div>
<p><?php echo $UT." - ".$Designation." - ".$Company; ?></p></div>
<textarea id="posting" name="posting" rows="2" cols="50" placeholder="Share something here..."></textarea>
<div class="clear"></div>
<hr>
</div>
<div class="fileUpload btn btn-default">
<span><i class="fa fa-camera-retro" style="margin-right: 6px;" aria-hidden="true"></i>Upload Image</span>
<input type="file" class="upload" />
</div>
<div>
<input class="postall btn btn-primary pull-right" type="submit" onClick="UserPost()" value="Post">
</div>
<div class="clear"></div>
</div>
<!-- Loading User Posts -->
<div id="mainsectionID">
<div id="results"><!-- results appear here as list --></div>
</div>
<script>
(function($){
$.fn.loaddata = function(options) {// Settings
var settings = $.extend({
loading_gif_url : "images/ajax-loader.gif", //url to loading gif
end_record_text : 'No more records found!', //no more records to load
data_url : 'fetch_pages.php', //url to PHP page
start_page : 1 //initial page
}, options);
var el = this;
loading = false;
end_record = false;
contents(el, settings); //initial data load
$(window).scroll(function() { //detact scroll
if($(window).scrollTop() + $(window).height() >= $(document).height()){ //scrolled to bottom of the page
contents(el, settings); //load content chunk
}
});
};
//Ajax load function
function contents(el, settings){
var load_img = $('<img/>').attr('src',settings.loading_gif_url).addClass('loading-image'); //create load image
var record_end_txt = $('<div/>').text(settings.end_record_text).addClass('end-record-info'); //end record text
if(loading == false && end_record == false){
loading = true; //set loading flag on
el.append(load_img); //append loading image
$.post( settings.data_url, {'page': settings.start_page}, function(data){ //jQuery Ajax post
if(data.trim().length == 0){ //no more records
el.append(record_end_txt); //show end record text
load_img.remove(); //remove loading img
end_record = true; //set end record flag on
return; //exit
}
loading = false; //set loading flag off
load_img.remove(); //remove loading img
el.append(data); //append content
settings.start_page ++; //page increment
})
}
}
})(jQuery);
$("#results").loaddata(); //load the results into element
</script>
fetch_pages.php code-
<?php
session_start();
include 'db.php'; //include config file
$UserID=$_SESSION['uid'];
$UserType=$_SESSION['utype'];
$GLOBALS['lks']=0;
$GLOBALS['cmnts']=0;
$GLOBALS['disabled']="";
//sanitize post value
$page_number = filter_var($_POST["page"], FILTER_SANITIZE_NUMBER_INT, FILTER_FLAG_STRIP_HIGH);
//throw HTTP error if page number is not valid
if(!is_numeric($page_number)){
header('HTTP/1.1 500 Invalid page number!');
exit();
}
//get current starting point of records
$position = (($page_number-1) * $item_per_page);
?>
<!---post start -->
<?php
//fetch records using page position and item per page.
$results = $linkID1->query("select slno,posts,img_link,video_link,likes,comments,shares,post_date,post_time,UserID from user_posts where UserID='$UserID' or UserID in(select MyFriendsUserID from user_connections where MyUserID='$UserID') or UserID in(select MyUserID from user_connections where MyFriendsUserID='$UserID') order by slno desc LIMIT $position, $item_per_page")
or
die(mysqli_error());
//output results from database
?>
<?php
while($row = mysqli_fetch_array($results))
{ //fetch values
$CUID=$row['UserID'];
$stmt = $linkID1->prepare("select Name,Company,Designation,UserType from user_details where UserID=?");
$stmt->bind_param("s", $CUID);
$stmt->execute();
$stmt->bind_result($Name2,$Company2,$Designation2,$UType);
$stmt->fetch();
$stmt->close();
$UT2='';
if($UType=='A')
{
$UT2='Advertiser';
}
else if($UType=='P')
{
$UT2='Publisher';
}
$stmt = $linkID1->prepare("select ProfilePic from user_picture where UserID=?");
$stmt->bind_param("s", $CUID);
$stmt->execute();
$stmt->bind_result($PPic);
$stmt->fetch();
$stmt->close();
?>
<div class="mainsection">
<div>
<div class="pull-left postimage"><?php echo "<img src=profile_pic/".$PPic ." />"; ?></div>
<div class="pull-left posttext">
<div class="postname"><?php echo $Name2; ?></div>
<p><?php echo $UT2." - ".$Designation2." - ".$Company2; ?></p></div>
<div class="clear"></div>
<div class="postdowntxt"><p><?php echo $row['posts']; ?></p></div>
<hr>
</div>
<div class="btnclasess" id="likescommentID<?php echo $row[slno]; ?>">
<div class="likescomment"><?php dataLC($linkID1, $row['slno'],$CUID); ?><a style="padding-right: 7px" href="#"><?php if($GLOBALS['lks']==0){echo '';}else{ echo $GLOBALS['lks']." Likes"; } ?></a><?php if($GLOBALS['cmnts']==0){echo '';}else{ echo $GLOBALS['cmnts']." Comments"; } ?></div>
<div class="pull-left likebtn"><button <?php echo $disabled; ?> class="btn" id="likeButton<?php echo $row[slno]; ?>" onClick="connect(<?php echo $row[slno]; ?>)"><i class="fa fa-thumbs-up" style="margin-right: 6px;"></i>Like</button></div>
<button class="pull-left btnhideshow show_hide" data-toggle="collapse" data-target="#demo<?php echo $row['slno']; ?>"><li class="fa fa-comments show_hide" style="margin-right: 6px;"></li>Comment</button>
<button class="pull-left btnhideshow show_hide"><li class="fa fa-share-alt show_hide" style="margin-right: 6px;"></li>Share</button>
<div class="clear"></div>
<div class="clear"></div>
</div>
<!-- Display All Comments -->
<div id="myModal<?php echo $row['slno']; ?>" class="modal">
<div id="DialogDiv<?php echo $row['slno']; ?>">
<!-- Modal content -->
<div class="modal-content" id="modalDialog<?php echo $row['slno']; ?>">
<p class="popupheading"><?php if($GLOBALS['cmnts']==0){echo '';}else{ echo $GLOBALS['cmnts']." Comments"; } ?></p>
<?php
$result2 = $linkID1->query("select upc.slno,upc.Comment,upc.CommentedUserID,up.ProfilePic from user_posts_comments upc join user_picture up on upc.CommentedUserID=up.UserID where PostID='$row[slno]' order by upc.slno")
or
die(mysqli_error());
while($row2 = mysqli_fetch_array($result2))
{
?>
<div class="pull-left commnetprofile"><?php echo "<img src=profile_pic/".$row2['ProfilePic']." />"; ?></div>
<div class="pull-right commentextstyle commentandreply">
<?php echo $row2['Comment']; ?>
</div>
<div class="pull-left likebtn"><i class="fa fa-reply" style="margin-right: 6px;"></i>Reply</div>
<!--<div class="pull-left likebtn"><i class="fa fa-thumbs-up" style="margin-right: 6px;"></i>Like</div>-->
<div class="clear"></div>
<div id="nReply2<?php echo $row2['slno']; ?>" class="collapse">
<div>
<input class="replybox" type="text" id="nReplyBox2<?php echo $row2['slno']; ?>" onkeyup="enter_reply2(<?php echo $row2['slno']; ?>,<?php echo $CUID; ?>,<?php echo $row['slno']; ?>);">
</div>
</div>
<div class="clear"></div>
<!-- Nested Comments Starts -->
<div id="NestedCmntsDialog" class="nestedcmnts">
<?php
$result3 = $linkID1->query("select upcr.slno,upcr.PostID,upcr.ReplyTo,upcr.ReplyBy,upcr.Comments,up.ProfilePic from user_posts_comments_reply upcr join user_picture up on upcr.ReplyBy=up.UserID where upcr.PostID='$row2[slno]' and (upcr.ReplyTo='$row2[CommentedUserID]' or upcr.ReplyBy='$row2[CommentedUserID]') order by upcr.slno")
or
die(mysqli_error());
while($row3 = mysqli_fetch_array($result3))
{
?>
<div class="pull-left commnetprofile"><?php echo "<img src=profile_pic/".$row3['ProfilePic']." />"; ?></div>
<div class="pull-right commentextstyle commentandreply">
<?php echo $row3['Comments']; ?>
</div>
<div class="pull-left likebtn"><i class="fa fa-reply" style="margin-right: 6px;"></i>Reply</div>
<div class="clear"></div>
<div id="nReply2<?php echo ($row3['slno'] * $row3['slno'])+$row3['PostID']; ?>" class="collapse">
<div>
<input class="replybox" type="text" id="nReplyBox2<?php echo ($row3['slno'] * $row3['slno'])+$row3['PostID']; ?>" onkeyup="enter_nested_reply2(<?php echo $row3['slno']; ?>,<?php echo $row3['ReplyBy']; ?>,<?php echo $row['slno']; ?>,<?php echo $row3['PostID']; ?>);">
</div>
</div>
<!--<div class="pull-left likebtn"><i class="fa fa-thumbs-up" style="margin-right: 6px;"></i>Like</div>-->
<div class="clear"></div>
<?php
}
?>
</div>
<!-- Nested Comments Ends -->
<?php
}
?>
<div class="invidone">Close</div>
</div>
</div>
</div>
<!-- Display All Comments -->
<div class="slidingDiv collapse" id="demo<?php echo $row['slno']; ?>">
<div class="viewallcomments">View All Comments</div>
<div class="allcomment" id="commentsLoad<?php echo $row['slno']; ?>">
<?php
$result2 = $linkID1->query("select upc.slno,upc.Comment,upc.CommentedUserID,up.ProfilePic from user_posts_comments upc join user_picture up on upc.CommentedUserID=up.UserID where upc.PostID='$row[slno]' order by upc.slno desc limit 3")
or
die(mysqli_error());
while($row2 = mysqli_fetch_array($result2))
{
?>
<!-- Showing Top 3 Comments -->
<div id="nestedReplyDiv<?php echo $row['slno']; ?>">
<div class="pull-left commnetprofile"><?php echo "<img src=profile_pic/".$row2['ProfilePic']." />"; ?></div>
<div class="pull-right commentextstyle commentandreply">
<?php echo $row2['Comment']; ?>
</div>
<div class="pull-left likebtn"><i class="fa fa-reply" style="margin-right: 6px;"></i>Reply</div>
<div class="clear"></div>
<div id="nReply<?php echo $row2['slno']; ?>" class="collapse">
<div>
<input class="replybox" type="text" id="nReplyBox<?php echo $row2['slno']; ?>" onkeyup="enter_reply(<?php echo $row2['slno']; ?>,<?php echo $CUID; ?>);">
</div>
</div>
<!--<div class="pull-left likebtn"><i class="fa fa-thumbs-up" style="margin-right: 6px;"></i>Like</div>-->
<div class="clear"></div>
<!-- Nested Comments Starts -->
<div id="NestedCmnts" class="nestedcmnts">
<?php
$result3 = $linkID1->query("select upcr.slno,upcr.PostID,upcr.ReplyTo,upcr.ReplyBy,upcr.Comments,up.ProfilePic from user_posts_comments_reply upcr join user_picture up on upcr.ReplyBy=up.UserID where upcr.PostID='$row2[slno]' and (upcr.ReplyTo='$row2[CommentedUserID]' or upcr.ReplyBy='$row2[CommentedUserID]') order by upcr.slno")
or
die(mysqli_error());
while($row3 = mysqli_fetch_array($result3))
{
?>
<div class="pull-left commnetprofile"><?php echo "<img src=profile_pic/".$row3['ProfilePic']." />"; ?></div>
<div class="pull-right commentextstyle commentandreply">
<?php echo $row3['Comments']; ?>
</div>
<div class="pull-left likebtn"><i class="fa fa-reply" style="margin-right: 6px;"></i>Reply</div>
<div class="clear"></div>
<div id="nReply<?php echo ($row3['slno'] * $row3['slno'])+$row3['PostID']; ?>" class="collapse">
<div>
<input class="replybox" type="text" id="nReplyBox<?php echo ($row3['slno'] * $row3['slno'])+$row3['PostID']; ?>" onkeyup="enter_nested_reply(<?php echo $row3['slno']; ?>,<?php echo $row3['ReplyBy']; ?>,<?php echo $row['slno']; ?>,<?php echo $row3['PostID']; ?>);">
</div>
</div>
<!--<div class="pull-left likebtn"><i class="fa fa-thumbs-up" style="margin-right: 6px;"></i>Like</div>-->
<div class="clear"></div>
<?php
}
?>
</div>
<!-- Nested Comments Ends -->
</div>
<?php
}
?>
</div>
<textarea id="commentarea<?php echo $row[slno]; ?>" class="secondtextareay pull-left" rows="2" cols="50" placeholder="Post comments here..." onkeyup="enter_comment(<?php echo $row['slno']; ?>,<?php echo $CUID; ?>);"></textarea>
<!--<div class="fileUpload second_fileupload btn btn-default pull-left">
<span><i class="fa fa-camera-retro" style="margin-right: 6px;" aria-hidden="true"></i></span>
<input type="file" class="upload" />
</div>-->
<div class="clear"></div>
</div>
</div>
<?php
}
?>
<!--post end-->
<?php
function dataLC($linkID1, $val, $CUID)
{
$UserID=$CUID;
$LgUserID=$_SESSION['uid'];
$stmt = $linkID1->prepare("select likes,comments from user_posts where slno=?");
$stmt->bind_param("s", $val);
$stmt->execute();
$stmt->bind_result($lksD,$cmntsD);
$stmt->fetch();
$stmt->close();
$GLOBALS['lks']=$lksD;
$GLOBALS['cmnts']=$cmntsD;
$stmt = $linkID1->prepare("select count(slno) from user_posts_likes where MyUserID=? and FrUserID=? and PostID=?");
$stmt->bind_param("sss", $UserID,$UserID,$val);
$stmt->execute();
$stmt->bind_result($cnt);
$stmt->fetch();
$stmt->close();
if($cnt>=1)
{
$GLOBALS['disabled']="disabled";
}
else
{
$GLOBALS['disabled']="enabled";
}
$stmt = $linkID1->prepare("select count(slno) from user_posts_likes where MyUserID=? and FrUserID=? and PostID=?");
$stmt->bind_param("sss", $UserID,$LgUserID,$val);
$stmt->execute();
$stmt->bind_result($cnt2);
$stmt->fetch();
$stmt->close();
if($cnt2>=1)
{
$GLOBALS['disabled']="disabled";
}
else
{
$GLOBALS['disabled']="enabled";
}
$stmt = $linkID1->prepare("select count(slno) from user_posts_likes where MyUserID=? and FrUserID=? and PostID=?");
$stmt->bind_param("sss", $LgUserID,$UserID,$val);
$stmt->execute();
$stmt->bind_result($cnt3);
$stmt->fetch();
$stmt->close();
if($cnt3>=1)
{
$GLOBALS['disabled']="disabled";
}
else
{
$GLOBALS['disabled']="enabled";
}
}
?>
<script>
$('.btn').on('click', function(e)
{
$(this).prop('disabled',true); });
</script>
<script>
function UserPost() {
var x = document.getElementById('posting').value;
var timezone_offset_minutes = new Date().getTimezoneOffset();
timezone_offset_minutes = timezone_offset_minutes == 0 ? 0 : -timezone_offset_minutes;
$.ajax({
type: "POST",
url: "user-post.php?p="+x+"&tz="+timezone_offset_minutes,
success: function(data) {
$("#mainsectionID").load(" #mainsectionID");
document.getElementById('posting').value='';
}
});
}
</script>
<script type="text/javascript">
function connect(num) {
$.ajax({
type: "POST",
url: "user-likes.php?id="+num,
success: function(data) {
if(data=='1')
{
$("#likescommentID"+num).load(" #likescommentID"+num);
}
}
});
}
function enter_comment(postid,userpostedid) {
if (event.keyCode == 13 && event.shiftKey) {
// shift+enter pressed
}
else if(event.keyCode == 13){
//enter key pressed
var cmnt = document.getElementById('commentarea'+postid).value;
$.ajax({
type: "POST",
url: "user-comments.php?id="+postid+"&cmnt="+cmnt,
success: function(data2) {
if(data2=='1')
{
$("#commentsLoad"+postid).load(" #commentsLoad"+postid);
$("#likescommentID"+postid).load(" #likescommentID"+postid);
}
}
});
document.getElementById('commentarea'+postid).value='';
}
else{
//nothing
}
}
</script>
<script type="text/javascript">
function enter_reply(slno,userpostedid) {
if (event.keyCode == 13 && event.shiftKey) {
// shift+enter pressed
}
else if(event.keyCode == 13){
//enter key pressed
var cmnt = document.getElementById('nReplyBox'+slno).value;
$.ajax({
type: "POST",
url: "user-comments-reply.php?id="+slno+"&cmnt="+cmnt,
success: function(data2) {
if(data2=='1')
{
$("#commentsLoad"+slno).load(" #commentsLoad"+slno);
}
}
});
document.getElementById('nReplyBox'+slno).value='';
}
else{
//nothing
}
}
function enter_reply2(slno,userpostedid,dno) {
if (event.keyCode == 13 && event.shiftKey) {
// shift+enter pressed
}
else if(event.keyCode == 13){
//enter key pressed
var cmnt = document.getElementById('nReplyBox2'+slno).value;
$.ajax({
type: "POST",
url: "user-comments-reply.php?id="+slno+"&cmnt="+cmnt,
success: function(data2) {
if(data2=='1')
{
$("#DialogDiv"+dno).load(" #DialogDiv"+dno);
//$("#modalDialog"+dno).load(" #modalDialog"+dno);
}
}
});
document.getElementById('nReplyBox2'+slno).value='';
}
else{
//nothing
}
}
</script>
<script type="text/javascript">
function enter_nested_reply(slno,userpostedid,divNo,pid) {
if (event.keyCode == 13 && event.shiftKey) {
// shift+enter pressed
}
else if(event.keyCode == 13){
//enter key pressed
var tot=(slno*slno)+pid;
var cmnt = document.getElementById('nReplyBox'+tot).value;
$.ajax({
type: "POST",
url: "user-comments-reply-nested.php?id="+slno+"&cmnt="+cmnt+"&upid="+userpostedid,
success: function(data2) {
if(data2=='1')
{
$("#nestedReplyDiv"+divNo).load(" #nestedReplyDiv"+divNo);
}
}
});
document.getElementById('nReplyBox'+tot).value='';
}
else{
//nothing
}
}
function enter_nested_reply2(slno,userpostedid,divNo,pid) {
if (event.keyCode == 13 && event.shiftKey) {
// shift+enter pressed
}
else if(event.keyCode == 13){
//enter key pressed
var tot=(slno*slno)+pid;
var cmnt = document.getElementById('nReplyBox2'+tot).value;
$.ajax({
type: "POST",
url: "user-comments-reply-nested.php?id="+slno+"&cmnt="+cmnt+"&upid="+userpostedid,
success: function(data2) {
if(data2=='1')
{
$("#DialogDiv"+divNo).load(" #DialogDiv"+divNo);
//$("#modalDialog"+divNo).load(" #modalDialog"+divNo);
}
}
});
document.getElementById('nReplyBox2'+tot).value='';
}
else{
//nothing
}
}
</script>
<script>
function LoadComment(num) {
var modal2 = document.getElementById('myModal'+num);
var span2 = document.getElementById("close3");
span2.onclick = function() {
modal2.style.display = "none";
}
window.onclick = function(event) {
if (event.target == modal2) {
modal2.style.display = "none";
}
}
var x = document.getElementById('myBtn2');
modal2.style.display = "block";
}
</script>
Problem resolved. Called the pagination again in the success method of ajax.

Clearing a DB call after you close modal

On my about the artist page when you click on the words button, and the will open a modal that gets information from a DB. Right now when you click on one artist button, close the modal, and then click on another artist both artist information will pop up. What I am trying to do is make sure the information only shows one artist at a time. I'm not sure if there is an issue with my ajax, or my model.
Here is a link to my live site now
Model
<?php
class Artist_get_model extends CI_Model {
function getData() {
// $query = $this->db->get_where("artist_content", array(" " => $page));
$query = $this->db->query("SELECT * from artist_content");
return $query;
}
// FIRST LAST NAME
// MODEL CHANGES
// SELECT * from artist_content" where lastname =
function modalData($lastname) {
$query = $this->db->query("SELECT * FROM artist_content WHERE last_name = '$lastname'");
return $query;
// return $lastname;
}
}
?>
PHP Artist Page
<?php
// echo $query->num_rows();
echo '<div class="container">';
echo '<div style="margin-top: 13%;" class=" artistHeader page-header">';
echo '<h1>Meet the artist</h1>';
echo '</div>';
echo '</div>';
echo '<div class="panel panel-default profile">';
echo ' <div class="panel-body">';
echo '<div class="container-fluid">';
echo '<div class="row">';
for( $i = 0 ; $i < $query->num_rows() ; $i++ ){
$row = $query->row_array($i);
// echo $row['workLink_img2'];
// for()
// echo '<div class="row"';
echo '<div id="noPadding" class="col-md-4">';
echo '<div class="thumbnail noPadding">';
// PROFILE IMG
echo '<img src="'.$row['profile_img'].'" alt=""></img>';
echo '<div class="caption">';
// NAME
echo '<h3 class="artistName">'.$row['first_name'].' '.$row['last_name'].'</h3>';
echo '<p><a class="button btn btn-primary " id="hello" role="button" data-toggle="modal" data-target="#myModal" data-artist="'.$row['last_name'].'">Words</a>';
echo '</div>';
echo '</div>';
echo "</div>";
// echo "</div>";
// Modal
// Modal content
echo '<div id="myModal" class="modal fade" role="dialog">';
echo '<div class="modal-dialog modal-lg">';
echo '<div class="modal-content">';
echo '<div class="modal-header">';
echo '<button type="button" class="close" data-dismiss="modal">×</button>';
// GET NAME FROM DB
echo '<h4 class="modal-title">'.$row['first_name'].' '.$row['last_name'].' </h4>';
echo '</div>';
echo '<div class="modal-body">';
echo '<div class=" artistInfo containter-fluid">';
// LOAD PHP FILE
echo '</div>';
echo '</div>';
echo '<div class="modal-footer">';
echo '<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>';
echo '</div>';
echo '</div>';
echo '</div>';
echo '</div>';
<script>
$(document).ready(function(){
$(".button").one("click", function(){
$.ajax({
type: "POST",
url: "/Artists/modal",
data: ({lastname: $(this).attr("data-artist") }),
success: function(result){
$(".artistInfo").append(result);
}});
});
});
Modal
<?php
for( $i = 0 ; $i < $artist->num_rows() ; $i++ ){
$row = $artist->row_array($i);
echo '<img class="pull-left img-responsive col-md-8" src=" '.$row['profile_img'].' ">';
echo '<div class="row">';
// SIDE IMG
echo '<a href="'.$row['workLink_img1'].'">';
echo '<img id="partsIm "class=" col-sm-4 pull-left img-thumbnail" src="'.$row['work_img1'].'"></img>';
echo '</a>';
// SIDE IMG
echo '<a href="'.$row['workLink_img2'].'">';
echo '<img id="partsIm" class="col-sm-4 pull-left img-thumbnail" src="'.$row['work_img2'].'"></img>';
echo '</a>';
// TEXT
echo '<p style="clear:both">'.$row['text'].'</p> ';
echo '</div>';
echo '</div>';
}
?>
It's in your button click event:
$(".button").one("click", function(){
$.ajax({
type: "POST",
url: "/Artists/modal",
data: ({lastname: $(this).attr("data-artist") }),
success: function(result){
//you're appending multiple data here
// $(".artistInfo").append(result);
// this instead:
$(".artistInfo").html(result);
}
});
});
});
lets empty it first since ajax can have a time lag...that way any time it takes to get new data it won't be displaying old data:
$(".button").on("click", function(){
$(".artistInfo").empty();// clear old html out
$.ajax({
type: "POST",
url: "/Artists/modal",
data: ({lastname: $(this).attr("data-artist") }),
success: function(result){
$(".artistInfo").append(result);
}});
});
append() adds to existing html and does not remove it thus you kept adding each time. If element is empty it won't matter what insertion method is used
NOTE: switched to on() instead of one() which is only intended to be used for a single event

Facebook and Twitter Share button not appearing after call with $.ajax

I am working on a simple script which is getting all the images from instagram.
And i have very strange problem with Facebook share button.
Here is my current script:
<?PHP
function callInstagram($url)
{
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => 2
));
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
$tag = Mage::getStoreConfig('vivastags/vivasgroup/instagra_tag');
$tag_additional = Mage::getStoreConfig('vivastags/vivasgroup/instagram_tag');
$client_id = "1e0f576fbdb44e299924a93cace24507";
$Next_URL = $_GET["nexturl"];
if($Next_URL == ""){
$url = 'https://api.instagram.com/v1/tags/'.$tag.'/media/recent?client_id='.$client_id.'&count=24';
} else {
$url = $Next_URL;
}
$Next_URL_Additional = $_GET["nexturl_add"];
if($Next_URL_Additional == ""){
$url_add = 'https://api.instagram.com/v1/tags/'.$tag_additional.'/media/recent?client_id='.$client_id.'&count=24';
} else {
$url_add = $Next_URL_Additional;
}
$inst_stream = callInstagram($url);
$results = json_decode($inst_stream, true);
$maxid = $results['pagination']['next_max_id'];
$nexturl = $results['pagination']['next_url'];
$inst_stream_add = callInstagram($url_add);
$results_add = json_decode($inst_stream_add, true);
$maxid_add = $results_add['pagination']['next_max_id'];
$nexturl_add = $results_add['pagination']['next_url'];
//Now parse through the $results array to display your results...
?>
<div class="holder" style="display:block;margin-left:70px;">
<?PHP
foreach($results['data'] as $item){
$image_link = $item['images']['thumbnail']['url'];
$big_image = $item['images']['standard_resolution']['url'];
$Profile_name = $item['user']['username'];
$PostID = $item['id'];
$Full_name = $item['user']['full_name'];
$Profile_Picture = $item['user']['profile_picture'];
$link = $item['link'];
$NotParsedString = Mage::getStoreConfig('vivastags/vivasgroup/instagra_forbiden_ids');
if(!in_array($PostID, explode(",", $NotParsedString))) {
?>
<a class="fancybox" rel="gallery1" href="#<?PHP echo $PostID;?>" id-za-premahvane="<?PHP echo $PostID;?>">
<img src="<?PHP echo $image_link; ?>" id="InstaBlock"/>
</a>
<div id="<?PHP echo $PostID;?>" style="display:none;">
<img src="<?PHP echo $big_image;?>" style="width:75%;">
<div style="display:block;clear:both;width:100%;">
<div style="display:block;width:200px;margin-top:10px;clear:both;margin-left:auto;margin-right:auto;">
<div style="display:block;">
<div class="fb-share-button" data-href="<?PHP echo $link; ?>" data-layout="button"></div>
</div>
<div style="display:block;position:absolute;margin-top:-20px;margin-left:100px;">
Tweet
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
</div>
<div style="display:block;position:absolute;margin-top:-20px;margin-left:180px;">
<a href="https://www.pinterest.com/pin/create/button/
?url=<?PHP echo $link; ?>
&media=<?PHP echo $big_image;?>
&description=Next%20stop%3A%20Pinterest"
data-pin-do="buttonPin"
target="_blank">
<img src="//assets.pinterest.com/images/pidgets/pin_it_button.png" />
</a>
</div>
</div>
<div style="display:block;margin-left:auto;margin-right:auto;margin-top:20px;">
<img src="<?PHP echo $Profile_Picture;?>" width="50px;"> <b>#<?PHP echo $Full_name;?></b>
</div>
</div>
</div>
<?PHP
}
}
foreach($results_add['data'] as $item_add){
$image_link_add = $item_add['images']['thumbnail']['url'];
$big_image_add = $item_add['images']['standard_resolution']['url'];
$Profile_name_add = $item_add['user']['username'];
$PostID_add = $item_add['id'];
$Full_name_add = $item_add['user']['full_name'];
$Profile_Picture_add = $item_add['user']['profile_picture'];
$link_add = $item_add['link'];
$NotParsedString_add = Mage::getStoreConfig('vivastags/vivasgroup/instagra_forbiden_ids');
if(!in_array($PostID_add, explode(",", $NotParsedString_add))) {
?>
<a class="fancybox" rel="gallery1" href="#<?PHP echo $PostID_add;?>" id-za-premahvane="<?PHP echo $PostID_add;?>">
<img src="<?PHP echo $image_link_add; ?>" id="InstaBlock"/>
</a>
<div id="<?PHP echo $PostID_add;?>" style="display:none;">
<img src="<?PHP echo $big_image_add;?>" style="width:75%;">
<div style="display:block;clear:both;width:100%;">
<div style="display:block;width:200px;margin-top:10px;clear:both;margin-left:auto;margin-right:auto;">
<div style="display:block;">
<div class="fb-share-button" data-href="<?PHP echo $link_add; ?>" data-layout="button"></div>
</div>
<div style="display:block;position:absolute;margin-top:-20px;margin-left:100px;">
Tweet
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
</div>
<div style="display:block;position:absolute;margin-top:-20px;margin-left:180px;">
<a href="https://www.pinterest.com/pin/create/button/
?url=<?PHP echo $link_add; ?>
&media=<?PHP echo $big_image_add;?>
&description=Next%20stop%3A%20Pinterest"
data-pin-do="buttonPin"
target="_blank">
<img src="//assets.pinterest.com/images/pidgets/pin_it_button.png" />
</a>
</div>
</div>
<div style="display:block;margin-left:auto;margin-right:auto;margin-top:20px;">
<img src="<?PHP echo $Profile_Picture_add;?>" width="50px;"> <b>#<?PHP echo $Full_name_add;?></b>
</div>
</div>
</div>
<?PHP
}
}
?>
<div id="LoadedResults"></div>
</div>
<?PHP
$nextUrlEncoded_add = urlencode($Next_URL_Additional);
$nextUrlEncoded = urlencode($nexturl);
?>
<div id="Loading">
Моля, изчакайте...
</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
$(".fancybox").fancybox({
openEffect : 'none',
closeEffect : 'none',
'titlePosition' : 'inside',
'transitionIn' : 'none',
'transitionOut' : 'none'
});
var NextUrlLink = "";
var NextUrlLink_add = "";
var TimesScrolled = 0;
if (!NextUrlLink){
var nextUrl = "<?PHP echo $nexturl;?>";
}
if (NextUrlLink){
var nextUrl = NextUrlLink;
}
if (!NextUrlLink_add){
var nextUrl_add = "<?PHP echo $nexturl_add;?>";
}
if (NextUrlLink_add){
var nextUrl_add = NextUrlLink_add;
}
$(window).scroll(function() {
if (TimesScrolled < 6) {
var hT = $('.footer-banners').offset().top,
hH = $('.footer-banners').outerHeight(),
wH = $(window).height(),
wS = $(this).scrollTop();
if (wS > (hT+hH-wH)){
$('#Loading').show();
$.ajax({
url: 'getajaxlink.php',
type: 'POST',
dataType: 'html',
data: {
next_url: nextUrl
},
}).done(function ( html ) {
var data = JSON.parse(html);
NextUrlLink = data.next_url_link;
});
$.ajax({
url: 'getajaxlink_add.php',
type: 'POST',
dataType: 'html',
data: {
next_url_add: nextUrl_add
},
}).done(function ( html ) {
var datas = JSON.parse(html);
NextUrlLink_add = datas.next_url_link;
});
$.ajax({
url: 'ajax.php',
type: 'POST',
dataType: 'html',
data: {
next_url: nextUrl,
next_url_add: nextUrl_add
},
}).done(function ( html ) {
TimesScrolled = TimesScrolled + 1;
$('#LoadedResults').append( html);
$('#Loading').hide();
});
}
} else {
$('#LoadMore').show();
}
});
$( "#LoadMore" ).click(function() {
$('#Loading').show();
$.ajax({
url: 'ajax.php',
type: 'POST',
dataType: 'html',
data: {
next_url: nextUrl,
next_url_add: nextUrl_add
},
}).done(function ( html ) {
TimesScrolled = TimesScrolled + 1;
$('#LoadedResults').append( html);
$('#Loading').hide();
});
});
});
</script>
<button id="LoadMore">Зареди още..</button>
This script is loading more content when the user scrolls to div element with class footer-banners. It is calling an $.ajax function from the file ajax.php and here is the complete code for ajax.php:
<?PHP
error_reporting(E_ALL | E_STRICT);
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
$app = Mage::app();
Mage::app();
Mage::getSingleton('core/session', array('name' => 'frontend'));
ini_set('display_errors', 1);
function callInstagram($url)
{
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => 2
));
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
$client_id = "1e0f576fbdb44e299924a93cace24507";
$Next_URL = $_POST["next_url"];
$url = $Next_URL;
$Next_URL_add = $_POST["next_url_add"];
$url_add = $Next_URL_add;
$inst_stream = callInstagram($url);
$results = json_decode($inst_stream, true);
$maxid = $results['pagination']['next_max_id'];
$nexturl = $results['pagination']['next_url'];
//Now parse through the $results array to display your results...
foreach($results['data'] as $item){
$image_link = $item['images']['thumbnail']['url'];
$big_image = $item['images']['standard_resolution']['url'];
$Profile_name = $item['user']['username'];
$PostID = $item['id'];
$Full_name = $item['user']['full_name'];
$Profile_Picture = $item['user']['profile_picture'];
$link = $item['link'];
$NotParsedString = Mage::getStoreConfig('vivastags/vivasgroup/instagra_forbiden_ids');
if(!in_array($PostID, explode(",", $NotParsedString))) {
?>
<a class="fancybox" rel="gallery1" href="#<?PHP echo $PostID;?>" id-za-premahvane="<?PHP echo $PostID;?>">
<img src="<?PHP echo $image_link; ?>" id="InstaBlock"/>
</a>
<div id="<?PHP echo $PostID;?>" style="display:none;">
<img src="<?PHP echo $big_image;?>" style="width:75%;">
<div style="display:block;clear:both;width:100%;">
<div style="display:block;width:200px;margin-top:10px;clear:both;margin-left:auto;margin-right:auto;">
<div style="display:block;">
<div class="fb-share-button" data-href="<?PHP echo $link; ?>" data-layout="button"></div>
</div>
<div style="display:block;position:absolute;margin-top:-20px;margin-left:100px;">
Tweet
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
</div>
<div style="display:block;position:absolute;margin-top:-20px;margin-left:180px;">
<a href="https://www.pinterest.com/pin/create/button/
?url=<?PHP echo $link; ?>
&media=<?PHP echo $big_image;?>
&description=Next%20stop%3A%20Pinterest"
data-pin-do="buttonPin"
target="_blank">
<img src="//assets.pinterest.com/images/pidgets/pin_it_button.png" />
</a>
</div>
</div>
<div style="display:block;margin-left:auto;margin-right:auto;margin-top:20px;">
<img src="<?PHP echo $Profile_Picture;?>" width="50px;"> <b>#<?PHP echo $Full_name;?></b>
</div>
</div>
</div>
<?PHP
}
}
$inst_stream_add = callInstagram($url_add);
$results_add = json_decode($inst_stream_add, true);
$maxid_add = $results_add['pagination']['next_max_id'];
$nexturl_add = $results_add['pagination']['next_url'];
//Now parse through the $results array to display your results...
foreach($results_add['data'] as $item_add){
$image_link_add = $item_add['images']['thumbnail']['url'];
$big_image_add = $item_add['images']['standard_resolution']['url'];
$Profile_name_add = $item_add['user']['username'];
$PostID_add = $item_add['id'];
$Full_name_add = $item_add['user']['full_name'];
$Profile_Picture_add = $item_add['user']['profile_picture'];
$link_add = $item_add['link'];
$NotParsedString = Mage::getStoreConfig('vivastags/vivasgroup/instagra_forbiden_ids');
if(!in_array($PostID_add, explode(",", $NotParsedString_add))) {
?>
<a class="fancybox" rel="gallery1" href="#<?PHP echo $PostID_add;?>" id-za-premahvane="<?PHP echo $PostID_add;?>">
<img src="<?PHP echo $image_link_add; ?>" id="InstaBlock"/>
</a>
<div id="<?PHP echo $PostID_add;?>" style="display:none;">
<img src="<?PHP echo $big_image_add;?>" style="width:75%;">
<div style="display:block;clear:both;width:100%;">
<div style="display:block;width:200px;margin-top:10px;clear:both;margin-left:auto;margin-right:auto;">
<div style="display:block;">
<div class="fb-share-button" data-href="<?PHP echo $link_add; ?>" data-layout="button"></div>
</div>
<div style="display:block;position:absolute;margin-top:-20px;margin-left:100px;">
Tweet
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
</div>
<div style="display:block;position:absolute;margin-top:-20px;margin-left:180px;">
<a href="https://www.pinterest.com/pin/create/button/
?url=<?PHP echo $link_add; ?>
&media=<?PHP echo $big_image_add;?>
&description=Next%20stop%3A%20Pinterest"
data-pin-do="buttonPin"
target="_blank">
<img src="//assets.pinterest.com/images/pidgets/pin_it_button.png" />
</a>
</div>
</div>
<div style="display:block;margin-left:auto;margin-right:auto;margin-top:20px;">
<img src="<?PHP echo $Profile_Picture_add;?>" width="50px;"> <b>#<?PHP echo $Full_name_add;?></b>
</div>
</div>
</div>
<?PHP
}
}
I have very strange problem. I am using the same code for the both files, the main and ajax.php. When elements are loaded with ajax.php the Facebook and Twitter button are not appearing as intended.
Please take a look at the live demo: http://home.cosmeosp.eu/social
Scroll to the bottom and new content will be loaded, after that click on a random picture and check out the Twitter button, because the Facebook button is not even appearing. How can i fix that and where is the problem ?
Can you help me out?
Thanks in advance!
After the ajax call is complete, call this function: FB.XFBML.parse();
For example:
... ajax call
}).done(function(data){
// do something
FB.XFBML.parse();
});
And for twitter:
twttr.widgets.load()

Open Graph User variable gets null after authorization

I am using Facebook's Open Graph API to import a user's images from his/her account.
But when I click on the login button and it opens the URL, after authorization it asks me again to login.
Here is my index.php:
<?php
ini_set("display_errors",0);
if ( !defined('ABSPATH') )
require_once '../../../../wp-load.php';
include_once __DIR__."/fbmain.php";
include_once __DIR__."/facebook.php";
if(!session_id())session_start();
global $fbSiteUrl;
/*$base_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']!='off') ? 'https://' : 'http://';
$base_url .= $_SERVER['HTTP_HOST'];*/
$fbSiteUrl = COO_PLUGIN_URL."/create-own-object/plugin-facebook";//$base_url.substr(__DIR__,strpos(__DIR__,'/phase2-newer'));
/*if(isset($_GET['logout']) && $_GET['logout']=='yes'){
$user = null;
$facebook->logoutFromSite();
}*/
if (!$user){
?>
<div class="facebook_login_box" id='fbLoginBtn'>
<div class="text-center">
<img src="<?php echo $fbSiteUrl; ?>/Images/facebook_logo.png" alt="" >
</div>
<div class="fb_login">
<button type="button" class="fb_login_btn" style="margin-right: 90px;" onclick="authoriseToSocialMedia('<?php echo $loginUrl; ?>');">Login</button>
</div>
</div>
<?php
}// else { ?>
<!-- <div class="right_side">
</div> -->
<?php //} ?>
<img src="<?php echo $fbSiteUrl; ?>/Images/folder_fb.png" style="display:none;">
<!-- all time check if user session is valid or not -->
<?php
if ($user) {
?>
<div id ='FBcontent'>
<form id ='FBcontentFrm' method="post" action="index.php">
<div class="folderset" id="folderList">
<!-- Data retrived from user profile are shown here -->
<?php
$albums = $facebook->api("/me/albums");
foreach($albums['data'] as $album){
?>
<div class="box">
<a href="javascript:void(0);" onclick="showAlbum('<?php echo $album['id']; ?>')">
<img src="<?php echo $fbSiteUrl; ?>/Images/folder_fb.png">
<div style="clear: both;"></div><?php echo $album['name']; ?>
</a>
</div>
<?php
}
?>
<div class="clearfix"></div>
</div>
<div id="fbhtmlImage">
<!-- Album images are being loaded here. -->
</div>
</form>
<script>
if((this.window.focus() || !(this.window.closed)) && window.opener != null)
{
window.opener.document.getElementById('facebook_content').innerHTML = document.getElementById('FBcontent').innerHTML;
window.opener.document.getElementById("fbLoginBtn").style.visibility="hidden";
this.window.close();
}
</script>
</div>
<?php } ?>
<script type="text/javascript">
function backToAlbums(){
$('#fbhtmlImage').hide();
$('#fbmodal-footer').hide();
$('#folderList').show();
}
function showAlbum(albumId){
$('#loader_img').show();
<?php global $fbSiteUrl;?>
$('#folderList').hide();
var fbhtml = '';
fbhtml += '<div class="image_list addimage_box_col">\
<div class="row">\
<div class="col-lg-2 col-sm-3 col-xs-6">\
<a class="pink_btn" href="javascript: void(0);" onClick="backToAlbums();">Back</a>\
</div>\
</div>\
<div class="clearfix"></div>\
</div>';
$.ajax({
type: "GET",
url: "<?php echo $fbSiteUrl; ?>/fbphotos.php",
data: { albumId: albumId }
}).done(function(response) {
var response = jQuery.parseJSON(response );
var showBtn = false;
fbhtml += "<div class='image_list addimage_box_col'>\
<div class='row'>";
if(response['data'].length>0)
{
for(var x=0; x<response['data'].length; x++){
fbhtml += '<div class="col-lg-2 col-sm-3 col-xs-6" style="padding-top: 15px;"><div class="checkbox_left">';
fbhtml += '<input type="checkbox" class="css-checkbox" id="facebook_'+x+'" name="facebook[]" value="'+response['data'][x]['source']+'" />';
fbhtml += '<label class="css-label radGroup1" for="facebook_'+x+'"></label>';
fbhtml += '</div>';
fbhtml += '<div class="image_thumb">';
fbhtml += '<img class="bdr img-responsive center-block" src="'+response['data'][x]['source']+'" />';// style="width:100px !important; height:100px !important;" />';
fbhtml += '</div></div>';
showBtn = true;
}
}
else
{
fbhtml += '<div class="image_thumb">';
fbhtml += 'There are no image(s) in this album.';
fbhtml += '</div>';
}
fbhtml += "<input type='hidden' name='fb_copy' value='Copy Selected Files'>\
</div>\
<div class='row'>";
fbhtml += '<div class="col-lg-2 col-sm-3 col-xs-6" style="padding-bottom: 10px; padding-top: 10px;">';
if(showBtn == true)
{
fbhtml += "<input type='button' class='pink_btn' name='fb_copy' value='Copy Selected Files' onclick='moveImages($(\"#FBcontentFrm\").serialize())' />";
}
fbhtml += "</div>\
</div>\
</div>";
$('#fbhtmlImage').html(fbhtml);
$('#fbhtmlImage').show();
$('#loader_img').hide();
});
}
</script>
<script>
/*
function moveImages(){
$.post(SiteURL+"wp-content/themes/mydomain/moveSelectedImages.php", $("#FBcontent").serialize(),function(data){
alert(data);
} );
}*/
</script>

jquery delete selected comment

I have made a forum and I want the user to delete their comment if they don't want it.
Now it deletes the first post and not the post that they have clicked "delete" on.
How can I check that its the comment they click on that gets deleted?
I have made this:
$(function() {
$(".slet").click( function(event) {
event.preventDefault();
//$(this).css("background-color","#000");
var id = "<?=$deleteID?>";
//alert(id);
$("#forum_content").fadeOut();
});
});
and my php:
it is a little messy.
<?php foreach ($comments as $comment): ?>
<?php
if($comment->level == "admin")
{
echo '<div class="adminclass">';
}
?>
<div id="forum_content" class="content">
<div class="forum_comment">
<div class="forum_profil_img"><img width="90" height="90" src="<?php echo base_url();?>images/users/thumbs/<?php echo $query->profile_picture; ?>"></div><!-- forum_profil_img -->
<div class="forum_post_content">
<span class="post_navn"><?php echo anchor('profil/index/'.$comment->kommentar_brugernavn, $comment->kommentar_brugernavn); ?></span>
<span style="font-size:11px; margin-left:3px; color:#686868;"><i> Siger</i></span><br>
<div id="data"><?php echo nl2br($comment->indhold); ?></div><!-- data -->
</div><!-- forum_post_content -->
<div style="width:auto; float:right; color:#a0a0a0; clear:left; position:relative; bottom:-15px;" id="forum_dato">
<i>
<abbr class="timeago" title="<?php echo $comment->dato; ?>"><?php echo $comment->dato; ?></abbr>
<?php
if($this->session->userdata('logget_ind') == 1 &&
$this->session->userdata('username') == $comment->brugernavn &&
time() - $comment->time < 300)
{ echo "- <a href=''>Ret</a> - <a class='slet' href=''>Slet</a>";
$deleteID = $comment->commentID;
} ?>
</i>
</div><!-- forum_post_content -->
</div><!-- forum_comment -->
<?php if ($comment->level == "admin") { ?> <span class="admin-ribbon"></span></div> <?php } ?>
</div><!-- content -->
<?php endforeach ?>
On each page use a counter, on which you assign a unique id to each comment from as it's added. That way you can delete comments irrelevant of their order (original or ordered).
Change the line echo "- <a href=''>Ret</a> - <a class='slet' href=''>Slet</a>" to
echo "- <a href=''>Ret</a> - <a class='slet' id='slet-".$comment->commentID."' href=''>Slet</a>"
and the click handler to:
$(function() {
$(".slet").click( function(event) {
event.preventDefault();
//$(this).css("background-color","#000");
var id = $(this).attr("id").replace(/[^0-9]/g, "");
alert(id);
$("#forum_content").fadeOut();
});
});

Categories