I'm using PDO to connect the database and using OOP method in coding
this is how to get the posts and comments
class MyWeb{
public function SelectStatus($user_id){
try{
$DBC = new DBConnector();
$query = "SELECT * FROM users U, posts P where P.user_id_fk=U.user_id and U.user_id=:user_id_fk";
$params = array(":user_id_fk"=>$user_id);
$result = $DBC->SelectArray($query,$params);
if($result){
return $result;
} else throw new Exception("Post not selected!");
}catch(Exception $e){
echo "Caught Exception: ".$e->getMessage();
return null;
}
}
public function SelectComment($post_id){
try{
$DBC = new DBConnector();
$query = "SELECT * FROM comments C, users U WHERE C.user_id_fk = U.user_id and C.post_id_fk = :post_id_fk";
$params = array(":post_id_fk"=>$post_id);
$result = $DBC->SelectArray($query,$params);
if($result){
return $result;
} else throw new Exception("Comment not selected!");
}catch(Exception $e){
echo "Caught Exception: ".$e->getMessage();
return null;
}
}
}
and this how to call the functions and display posts and comments
<?php
$NewStatus = $session->SelectStatus($user_id);
if(!empty($NewStatus)){
foreach($NewStatus as $data){
$username = $data->username;
$post = $data->post;
$post_id = $data->post_id;
echo "".$username." | ".$post."";
$NewComment = $session->SelectComment($post_id);
if(!empty($NewComment)){
foreach($NewComment as $cdata){
echo $cdata->comment;
}
}
}
}
?>
But sadly I always get error -> Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\RIO\RIO\RAI\session_rai\includes\db.php on line 14
So, Any solutions for this case? Thanks.