What's new

Pano to mafix isa na lang

loktoy

Eternal Poster
Joined
Oct 20, 2014
Posts
1,166
Solutions
2
Reaction
103
Points
496
Age
30
kapag pinipindot ko yun content sa title.php nakaasssign na sya sa kanya kanya id hindi na nahahalo..
ang problima ko na lang po is kapag mag rereply po ako sa isang content at nag click ko ng submit..
wala na po syang display o output kahit ireload ko pa o irefresh wala tlga sya display pero kapag bumalik ako sa title.php at pinindot ko yun content na kung saan ako nag reply lalabas na yun reply message ko...

ito code ko sa
title.php
<?php include('dbconn.php'); ?>
<?php include('session.php'); ?>
<?php
$query = mysqli_query($conn,"SELECT *,UNIX_TIMESTAMP() - date_created AS TimeSpent from post LEFT JOIN user on user.user_id = post.user_id order by date_created DESC")or die(mysqli_error());
while($post_row=mysqli_fetch_array($query)){
$id = $post_row['post_id'];
$upid = $post_row['user_id'];
$posted_by = $post_row['firstname']." ".$post_row['lastname'];

?>
<?php echo $upid;?><a href="home.php?id=<?php echo $id;?>"><?php echo $post_row['content']; ?></a><br>
<?php }?>

ito naman code ko sa home.php

<!DOCTYPE html>
<html>
<head>
<title>POST AND COMMENT SYSTEM</title>
<?php include('dbconn.php'); ?>
<?php include('session.php'); ?>

<script src="vendors/jquery-1.7.2.min.js"></script>
<script src="vendors/bootstrap.js"></script>

</head>
<body>
<div id="container">
<br>
WELCOME!
<a href="title.php"><button><?php
echo $member_row['firstname']." ".$member_row['lastname'];
?> - Log Out</button></a>

<br>
<br>
<br>
WELCOME!
<a href="thread.php"><button><?php
echo $member_row['firstname']." ".$member_row['lastname'];
?> - thread</button></a>

<br>
<?php

?>
<?php
if(isset($_GET['id'])){
$id = $_GET['id'];
$query = mysqli_query($conn,"SELECT *,UNIX_TIMESTAMP() - date_created AS TimeSpent from post LEFT JOIN user on user.user_id = post.user_id WHERE post_id = '$id' order by post_id DESC limit 1")or die(mysqli_error());
while($post_row=mysqli_fetch_array($query)){
$id = $post_row['post_id'];
$upid = $post_row['user_id'];
$posted_by = $post_row['firstname']." ".$post_row['lastname'];
?>
<a style="text-decoration:none; float:right;" href="deletepost.php<?php echo '?id='.$id; ?>"><button><font color="red">x</button></font></a>
<h3>Posted by: <a href="#"> <?php echo $posted_by; ?></a>
-
<?php
$days = floor($post_row['TimeSpent'] / (60 * 60 * 24));
$remainder = $post_row['TimeSpent'] % (60 * 60 * 24);
$hours = floor($remainder / (60 * 60));
$remainder = $remainder % (60 * 60);
$minutes = floor($remainder / 60);
$seconds = $remainder % 60;
if($days > 0)
echo date('F d, Y - H:i:sa', $post_row['date_created']);
elseif($days == 0 && $hours == 0 && $minutes == 0)
echo "A few seconds ago";
elseif($days == 0 && $hours == 0)
echo $minutes.' minutes ago';
?>
<br>
<br><?php echo $post_row['content']; ?></h3>
<form method="post">
<hr>
Comment:<br>
<input type="hidden" name="id" value="<?php echo $id; ?>">
<textarea name="comment_content" rows="2" cols="44" style="" placeholder=".........Type your comment here........" required></textarea><br>
<input type="submit" name="comment">
</form>

</br>

<?php
$comment_query = mysqli_query($conn,"SELECT * ,UNIX_TIMESTAMP() - date_posted AS TimeSpent FROM comment LEFT JOIN user on user.user_id = comment.user_id where post_id = '$id'") or die (mysqli_error());
while ($comment_row=mysqli_fetch_array($comment_query)){
$comment_id = $comment_row['comment_id'];
$comment_by = $comment_row['firstname']." ". $comment_row['lastname'];
?>
<br><a href="#"><?php echo $comment_by; ?></a> - <?php echo $comment_row['content']; ?>
<br>
<?php
$days = floor($comment_row['TimeSpent'] / (60 * 60 * 24));
$remainder = $comment_row['TimeSpent'] % (60 * 60 * 24);
$hours = floor($remainder / (60 * 60));
$remainder = $remainder % (60 * 60);
$minutes = floor($remainder / 60);
$seconds = $remainder % 60;
if($days > 0)
echo date('F d, Y - H:i:sa', $comment_row['date_posted']);
elseif($days == 0 && $hours == 0 && $minutes == 0)
echo "A few seconds ago";
elseif($days == 0 && $hours == 0)
echo $minutes.' minutes ago';
?>
<br>
<?php
}
}?>
<hr
&nbsp;
<?php
if ($u_id = $id){
?>



<?php }else{ ?>

<?php
} } ?>


<?php
if (isset($_POST['post'])){
$post_content = $_POST['post_content'];

mysqli_query($conn,"insert into post (content,date_created,user_id) values ('$post_content','".strtotime(date("Y-m-d h:i:sa"))."','$user_id') ")or die(mysqli_error());
header('location:home.php');
}
?>
<?php

if (isset($_POST['comment'])){
$comment_content = $_POST['comment_content'];
$post_id=$_POST['id'];

mysqli_query($conn,"insert into comment (content,date_posted,user_id,post_id) values ('$comment_content','".strtotime(date("Y-m-d h:i:sa"))."','$user_id','$post_id')") or die (mysqli_error());
header('location:home.php');
}
?>
</body>
<?php include('footer.php');?>
</html>
 
Based on the code you provided, it seems that the issue lies in your SQL query in the home.php file. The query selects the posts and comments based on the post ID, but it does not include a condition to retrieve the comments for each specific post. As a result, when you reload or refresh the page after submitting a comment, it only retrieves the post content without the associated comments.

To fix this issue, you need to modify your query to include the condition for retrieving comments specific to each post. Here is the modified code:

PHP:
$query = mysqli_query($conn,"SELECT *, UNIX_TIMESTAMP() - date_created AS TimeSpent FROM post LEFT JOIN user ON user.user_id = post.user_id WHERE post_id = '$id' ORDER BY post_id DESC LIMIT 1") or die(mysqli_error());
while($post_row = mysqli_fetch_array($query)){
    $id = $post_row['post_id']; 
    $upid = $post_row['user_id'];   
    $posted_by = $post_row['firstname']." ".$post_row['lastname'];
    ?>
    <!-- your existing code -->
    <?php
    $comment_query = mysqli_query($conn,"SELECT *, UNIX_TIMESTAMP() - date_posted AS TimeSpent FROM comment LEFT JOIN user ON user.user_id = comment.user_id WHERE post_id = '$id'") or die(mysqli_error());
    while($comment_row = mysqli_fetch_array($comment_query)){
        $comment_id = $comment_row['comment_id'];
        $comment_by = $comment_row['firstname']." ".  $comment_row['lastname'];
        ?>
        <!-- your existing code for displaying comments -->
        <?php
    }
}

With this modification, the query will retrieve the specific post based on the post ID and also retrieve the comments associated with that post. This should ensure that both the post and its comments are displayed correctly when you reload or refresh the page after submitting a comment.
 
Based on the code you provided, it seems that the issue lies in your SQL query in the home.php file. The query selects the posts and comments based on the post ID, but it does not include a condition to retrieve the comments for each specific post. As a result, when you reload or refresh the page after submitting a comment, it only retrieves the post content without the associated comments.

To fix this issue, you need to modify your query to include the condition for retrieving comments specific to each post. Here is the modified code:

PHP:
$query = mysqli_query($conn,"SELECT *, UNIX_TIMESTAMP() - date_created AS TimeSpent FROM post LEFT JOIN user ON user.user_id = post.user_id WHERE post_id = '$id' ORDER BY post_id DESC LIMIT 1") or die(mysqli_error());
while($post_row = mysqli_fetch_array($query)){
    $id = $post_row['post_id'];
    $upid = $post_row['user_id'];  
    $posted_by = $post_row['firstname']." ".$post_row['lastname'];
    ?>
    <!-- your existing code -->
    <?php
    $comment_query = mysqli_query($conn,"SELECT *, UNIX_TIMESTAMP() - date_posted AS TimeSpent FROM comment LEFT JOIN user ON user.user_id = comment.user_id WHERE post_id = '$id'") or die(mysqli_error());
    while($comment_row = mysqli_fetch_array($comment_query)){
        $comment_id = $comment_row['comment_id'];
        $comment_by = $comment_row['firstname']." ".  $comment_row['lastname'];
        ?>
        <!-- your existing code for displaying comments -->
        <?php
    }
}

With this modification, the query will retrieve the specific post based on the post ID and also retrieve the comments associated with that post. This should ensure that both the post and its comments are displayed correctly when you reload or refresh the page after submitting a comment.
ayaw pa din gumana
 
ayaw pa din gumana
I apologize for the confusion. It seems that there is an issue with the code. Upon reviewing it again, I noticed that there is an additional closing curly bracket (}) after the comment section that might be causing the problem. This extra closing curly bracket prematurely ends the loop, preventing the comments from being displayed.

To fix this issue, please remove the extra closing curly bracket (}) at the end of the code block. Here is the modified code:

PHP:
$query = mysqli_query($conn,"SELECT *, UNIX_TIMESTAMP() - date_created AS TimeSpent FROM post LEFT JOIN user ON user.user_id = post.user_id WHERE post_id = '$id' ORDER BY post_id DESC LIMIT 1") or die(mysqli_error());
while($post_row = mysqli_fetch_array($query)){
    $id = $post_row['post_id'];
    $upid = $post_row['user_id'];
    $posted_by = $post_row['firstname']." ".$post_row['lastname'];
    ?>
    <!-- your existing code -->
    <?php
    $comment_query = mysqli_query($conn,"SELECT *, UNIX_TIMESTAMP() - date_posted AS TimeSpent FROM comment LEFT JOIN user ON user.user_id = comment.user_id WHERE post_id = '$id'") or die(mysqli_error());
    while($comment_row = mysqli_fetch_array($comment_query)){
        $comment_id = $comment_row['comment_id'];
        $comment_by = $comment_row['firstname']." ".  $comment_row['lastname'];
        ?>
        <!-- your existing code for displaying comments -->
        <?php
    }
}
// Remove this extra curly bracket

After removing the extra curly bracket, save the file and try to reload or refresh the page. The comments should now be displayed properly along with the post content.
 
I apologize for the confusion. It seems that there is an issue with the code. Upon reviewing it again, I noticed that there is an additional closing curly bracket (}) after the comment section that might be causing the problem. This extra closing curly bracket prematurely ends the loop, preventing the comments from being displayed.

To fix this issue, please remove the extra closing curly bracket (}) at the end of the code block. Here is the modified code:

PHP:
$query = mysqli_query($conn,"SELECT *, UNIX_TIMESTAMP() - date_created AS TimeSpent FROM post LEFT JOIN user ON user.user_id = post.user_id WHERE post_id = '$id' ORDER BY post_id DESC LIMIT 1") or die(mysqli_error());
while($post_row = mysqli_fetch_array($query)){
    $id = $post_row['post_id'];
    $upid = $post_row['user_id'];
    $posted_by = $post_row['firstname']." ".$post_row['lastname'];
    ?>
    <!-- your existing code -->
    <?php
    $comment_query = mysqli_query($conn,"SELECT *, UNIX_TIMESTAMP() - date_posted AS TimeSpent FROM comment LEFT JOIN user ON user.user_id = comment.user_id WHERE post_id = '$id'") or die(mysqli_error());
    while($comment_row = mysqli_fetch_array($comment_query)){
        $comment_id = $comment_row['comment_id'];
        $comment_by = $comment_row['firstname']." ".  $comment_row['lastname'];
        ?>
        <!-- your existing code for displaying comments -->
        <?php
    }
}
// Remove this extra curly bracket

After removing the extra curly bracket, save the file and try to reload or refresh the page. The comments should now be displayed properly along with the post content.
ito po updated na code ko
<!DOCTYPE html>
<html>
<head>
<title>POST AND COMMENT SYSTEM</title>
<?php include('dbconn.php'); ?>
<?php include('session.php'); ?>

<script src="vendors/jquery-1.7.2.min.js"></script>
<script src="vendors/bootstrap.js"></script>

</head>
<body>
<div id="container">
<br>
WELCOME!
<a href="title.php"><button><?php
echo $member_row['firstname']." ".$member_row['lastname'];
?> - Log Out</button></a>

<br>
<br>
<br>
WELCOME!
<a href="thread.php"><button><?php
echo $member_row['firstname']." ".$member_row['lastname'];
?> - thread</button></a>

<br>
<?php

?>
<?php
if(isset($_GET['id'])){
$id = $_GET['id'];
$query = mysqli_query($conn,"SELECT *,UNIX_TIMESTAMP() - date_created AS TimeSpent from post LEFT JOIN user on user.user_id = post.user_id WHERE post_id = '$id' order by post_id DESC limit 1")or die(mysqli_error());
while($post_row=mysqli_fetch_array($query)){
$id = $post_row['post_id'];
$upid = $post_row['user_id'];
$posted_by = $post_row['firstname']." ".$post_row['lastname'];
?>
<?php
$comment_query = mysqli_query($conn,"SELECT *, UNIX_TIMESTAMP() - date_posted AS TimeSpent FROM comment LEFT JOIN user ON user.user_id = comment.user_id WHERE post_id = '$id'") or die(mysqli_error());
while($comment_row = mysqli_fetch_array($comment_query)){
$comment_id = $comment_row['comment_id'];
$comment_by = $comment_row['firstname']." ". $comment_row['lastname'];
?>


<a style="text-decoration:none; float:right;" href="deletepost.php<?php echo '?id='.$id; ?>"><button><font color="red">x</button></font></a>
<h3>Posted by: <a href="#"> <?php echo $posted_by; ?></a>
-
<?php
$days = floor($post_row['TimeSpent'] / (60 * 60 * 24));
$remainder = $post_row['TimeSpent'] % (60 * 60 * 24);
$hours = floor($remainder / (60 * 60));
$remainder = $remainder % (60 * 60);
$minutes = floor($remainder / 60);
$seconds = $remainder % 60;
if($days > 0)
echo date('F d, Y - H:i:sa', $post_row['date_created']);
elseif($days == 0 && $hours == 0 && $minutes == 0)
echo "A few seconds ago";
elseif($days == 0 && $hours == 0)
echo $minutes.' minutes ago';
?>
<br>
<br><?php echo $post_row['content']; ?></h3>
<form method="post">
<hr>
Comment:<br>
<input type="hidden" name="id" value="<?php echo $id; ?>">
<textarea name="comment_content" rows="2" cols="44" style="" placeholder=".........Type your comment here........" required></textarea><br>
<input type="submit" name="comment">
</form>

</br>

<?php
$comment_query = mysqli_query($conn,"SELECT * ,UNIX_TIMESTAMP() - date_posted AS TimeSpent FROM comment LEFT JOIN user on user.user_id = comment.user_id where post_id = '$id'") or die (mysqli_error());
while ($comment_row=mysqli_fetch_array($comment_query)){
$comment_id = $comment_row['comment_id'];
$comment_by = $comment_row['firstname']." ". $comment_row['lastname'];
?>
<br><a href="#"><?php echo $comment_by; ?></a> - <?php echo $comment_row['content']; ?>
<br>
<?php
$days = floor($comment_row['TimeSpent'] / (60 * 60 * 24));
$remainder = $comment_row['TimeSpent'] % (60 * 60 * 24);
$hours = floor($remainder / (60 * 60));
$remainder = $remainder % (60 * 60);
$minutes = floor($remainder / 60);
$seconds = $remainder % 60;
if($days > 0)
echo date('F d, Y - H:i:sa', $comment_row['date_posted']);
elseif($days == 0 && $hours == 0 && $minutes == 0)
echo "A few seconds ago";
elseif($days == 0 && $hours == 0)
echo $minutes.' minutes ago';
?>
<br>
<?php
}
}}?>
<hr
&nbsp;
<?php
if ($u_id = $id){
?>



<?php }else{ ?>

<?php
} } ?>


<?php
if (isset($_POST['post'])){
$post_content = $_POST['post_content'];

mysqli_query($conn,"insert into post (content,date_created,user_id) values ('$post_content','".strtotime(date("Y-m-d h:i:sa"))."','$user_id') ")or die(mysqli_error());
header('location:home.php');
}
?>
<?php

if (isset($_POST['comment'])){
$comment_content = $_POST['comment_content'];
$post_id=$_POST['id'];

mysqli_query($conn,"insert into comment (content,date_posted,user_id,post_id) values ('$comment_content','".strtotime(date("Y-m-d h:i:sa"))."','$user_id','$post_id')") or die (mysqli_error());
header('location:home.php');
}
?>
</body>
<?php include('footer.php');?>
</html>
 

Similar threads

Back
Top