Jump to content

Recommended Posts

Posted

Hi. I am getting this kind of an error. Maybe someone knows what i am doing wrong? 
 

Notice: Trying to get property 'total_posts' of non-object in C:\xampp\htdocs\pages\forum\forum.php on line 42

Here is the code: 
 

$update = 'SELECT 
				forum_id
			FROM 
				forum';
$update = $db -> prepare($update);
$update->execute();
while($row = $update -> fetch(PDO::FETCH_OBJ)){
	$post = 'SELECT 
				post_thread, 
				post_datestamp, 
				post_user,
				(SELECT COUNT(post_entry) FROM forum_post WHERE post_forum='.$row->forum_id.') AS total_posts
			FROM 
				forum_post 
			WHERE 
				post_forum='.$row->forum_id.' 
			AND 
				post_datestamp =(SELECT MAX(post_datestamp) FROM forum_post WHERE post_forum='.$row->forum_id.')';
	$post = $db -> prepare($post);
	$post->execute();
	$p_row = $post -> fetch(PDO::FETCH_OBJ);
	$num_of_p = $p_row->total_posts;
	if($num_of_p==null){
		$last_post_date = null;
		$last_post_thread = null;
		$post_user = null;
	}
	else{
		$last_post_date = $p_row->post_datestamp;
		$last_post_thread = $p_row->post_thread;
		$post_user = $p_row->post_user;
	}
	$post=null;
	
	$threads = 'SELECT count(thread_name) as total_threads FROM forum_thread WHERE thread_forum_id='.$row->forum_id.'';
	$threads = $db -> prepare($threads);
	$threads->execute();
	$t_row = $threads -> fetch(PDO::FETCH_OBJ);
	$num_of_t = $t_row->total_threads;
	$threads=null;

	$up_forum = 'UPDATE forum SET forum_threads=?, forum_replies=?, forum_lastpost_user =?, forum_lastpost_date =?, forum_lastpost_thread =? WHERE forum_id ='.$row->forum_id.'';
	$up_forum = $db->prepare($up_forum); 
	$up_forum->execute([$num_of_t, $num_of_p, $post_user, $last_post_date, $last_post_thread]);
	$up_forum=null;
}
$update=null;

 



×
×
  • Create New...