Jump to content

Recommended Posts

ok i have this script that is supposed to load the posts from the database , but it wont i just get a blank page ... this is a lot of code...

here is the home.php where im trying to get it to load

home.php

<?php 
$query = mysql_query("SELECT id,to_id,from_id,post,type,state,date FROM posts ORDER BY id DESC LIMIT 15");	
print posts($query);
if(mysql_num_rows($query)==0)
{
?>
<div class="no-info"><?php print $username ?> has not written any posts yet.</div>
<?php 
}
?>
</ul>
</div>
<div class="profile-right"></div>
<script>
loadPostsFunction();
var pageLoaded = "posts";
</script></div>
</body>

loadPostsFunction(); is in the javascript file here

sitewide.js

var loadedPosts = true;
function loadPostsFunction(){

var last_post_id = $(".stream > li:last").attr('id');
if(!get('id'))
{
var action = "&action="+action;	
}
$.ajax({
type: "POST",
url: "posts/load_posts.php",
data: "post_id="+last_post_id+""+action,
cache: false,
success: function(html){
var html = html.replace(/^\s+|\s+$/g, '');
if(html)
{
$(".stream > li:last").after(html);
}
var lpostid = $(".stream > li:last").attr('id');
if(last_id==lpostid)
{
$(window).unbind('scroll', loadPosts());
}

loadedPosts = true;
}
});	


}
function loadPosts()
{
if ($(window).height() + $(window).scrollTop() >= $(document).height()-600) 	
{
if(loadedPosts)
{
loadedPosts = false;

loadPostsFunction();

}
}

}


$(document).ready(function(){
$(window).scroll(function () {
loadPosts();
});
});


now here is the script that the javascript file is calling on.

Load_posts.php

<?php include("../includes.php");
$session = $logOptions_id;
$post_id = $_POST['post_id'];
$action = $_POST['action'];
if($session)
{
if($action)
{
$get_info = mysql_fetch_assoc(mysql_query("SELECT to_id FROM posts WHERE id='$post_id'"));	
$query = mysql_query("SELECT * FROM posts WHERE to_id=from_id AND id<'$post_id' AND state='0' ORDER BY id DESC LIMIT 25");
$row = mysql_fetch_assoc(mysql_query("SELECT * FROM posts WHERE to_id=from_id AND id<'$post_id' AND state='0' ORDER BY id ASC LIMIT 1"));
}

else
{
$get_info = mysql_fetch_assoc(mysql_query("SELECT to_id FROM posts WHERE id='$post_id'"));	
$user_id = $get_info['to_id'];
$query = mysql_query("SELECT * FROM posts WHERE to_id='$user_id' AND id<'$post_id' AND state='0' ORDER BY id DESC LIMIT 25");
$row = mysql_fetch_assoc(mysql_query("SELECT * FROM posts WHERE to_id='$user_id' AND id<'$post_id' AND state='0' ORDER BY id ASC LIMIT 1"));
}



print posts($query);
$last_id = $row['id'];

?>
<script>var last_id = <?php print $last_id?></script>
<?php 
}
?>

and in the code above you can see where it says "print posts($query);" that is in the next file

functions.php (segment where the function is)

function posts($query, $action_type)
{
$session = $logOpions_id;
if($action_type=="newPost")
{
$class = "class='new'";
}
else
{
$class = "";
}

while($row = mysql_fetch_array($query))
{
$id = $row['id'];
$to_id = $row['to_id'];
$from_id = $row['from_id'];
$post = stripslashes(linkify(nl2br(htmlentities($row['post']))));
$type = $row['type'];
$state = $row['state'];
$date = time_stamp($row['date']);

$name = name($from_id);
$photo = photo($from_id, 55);


$num_likes = mysql_num_rows(mysql_query("SELECT id FROM db_like WHERE post_id='$id'"));
if($num_likes == 0)
{
$num_likes = '';
}
else if($num_likes == 1)
{
$num_likes = $num_likes." person likes this";	
}
else
{
$num_likes = $num_likes." people like this";
}

$query_like = mysql_fetch_assoc(mysql_query("SELECT id FROM db_like WHERE post_id='$id' AND from_id='$session'"));
if($query_like)
{$like_unlike = "unlike";}
else
{$like_unlike = "like";}

if($from_id==$session)
{
$session_photo = "class='post-photo".$session."'";	
}else{$session_photo = "";}

if($action_type!="noLi")
{
?>
<li <?php print $class?> id="<?php print $id?>"><?php }?>
<div>
<div class="post-left"><img <?php $session_photo?> src="<?php print $photo?>" /></div>
<div class="post-right">
<!---ARROW-->
<div class="arrow-border"><div class="arrow"></div></div>
<!------->

<?php if($to_id==$session||$from_id==$session){?>
<div class="post-remove" onClick="remove_post('<?php print $id?>')">X</div>
<?php }?>



<!---COMMENTS--->
<div class="comment-wrapper">
<ul class="comments" id="comment-container<?php print $id?>">
<?php 
$query2 = mysql_query("SELECT * FROM comments WHERE post_id='$id' AND state='0' ORDER BY id ASC");
print comments($query2);
?>
</ul>
<div class="comment-post-wrapper" id="comment-wrapper<?php print $id?>">
<textarea class="comment-post" id="comment<?php print $id?>" onkeyup="limitText(this,350,'.character-count')" onclick="limitText(this,350,'.character-count')"></textarea>
<a class="comment-post-button" onClick="add_comment('<?php print $id?>','<?php print $to_id?>')">Comment</a>
</div>
</div>
<!---COMMENTS END--->
<?php if($action_type!="noLi")
{
?>
</li>
<?php }
}

}

Thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/255960-loading-posts-wont-work/
Share on other sites

couple things:

 

1. do you receive any back end syntax errors? make sure that you have error_reporting() set to E_ALL or -1

 

2. are you using debugging tools for the front end code? (firebug,chromes developer tools)? If not, you should be.

 

3.

var action = "&action="+action;	

 

this line stands out to me because it does not make a whole lot of sense from the context, and will disallow the request from being made.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.