What's new

Patulong po di po ako makaalis alis dito e.

loktoy

Eternal Poster
Joined
Oct 20, 2014
Posts
1,166
Solutions
2
Reaction
103
Points
496
Age
30
kapag po ako ay nag post ng isang content may output sya pag marereply ako good sya may ouput din..
ito po code ko sa sa textarea o paglalagay ng content..

thread.php

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Homepage</title>
<link rel= "stylesheet" href="../css/bootstrap.css">
<link rel= "stylesheet" href="../css/style.css">
<script src="../js/bootstrap.bundle.js"></script>
<script src="../js/style.js"></script>
<script src="../ajax/sweetalert2.all.min.js"></script>
<script src="../ajax/jquery-3.7.0.min.js"></script>

</head>
<body>
<div class="container col-md-6">
<div class="mb-5 text-center">
<h1>Discussion Thread</h1>
</div>
<form method="POST" action="home.php">
<label class="fw-bold mb-2" for="w3review">Content:</label>
<textarea name="post_content" class="form-control" id="post" rows="10" cols="50" placeholder="Your Content....."></textarea>
<div class="form-group mb-5 mt-2" style="text-align: right">
<input type="submit" name="post" class="w-25" value="Post" style="background-color:#0D52C7;">
<!-- <input class="col-md-3" type="submit" value="Post" style="background:#42A5F5";> -->
</div>
</div>
</form>

</body>
</html>

ngayon po ay nag ooutput o mag didisplay sya dito home.php.. so lalabas po yun content ginawa kosa thread.php dito po sa home.php pwede kna mag reply sa content ok na sya nakakapag reply naman sya..
ito 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
$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 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>

ngayon kasi may thread kna so nag lagay rin ako ng title.php kung saan icclick mo lang yun content mapupunta kna sa content nya na may mga reply kung knino lang may reply na content..
ngayon ang problima is kapag is kapag clinilick ko yun content sa title.php kahit alin content pareparehas yun reply lang kung anu huling reply ko sa content kung knino id maaapply nya sa lahat ng id o user

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 }?>
 
Based on your code, it looks like you are trying to display the content and comments for each post on the home.php page. However, when you click on a specific post from the title.php page, it only displays the latest comment for all posts instead of the comments specific to that post.

To fix this issue, you need to modify your code in home.php and title.php to ensure that only the comments for the selected post are displayed.

In home.php, you should modify the code for displaying comments to only fetch the comments for the current post:

PHP:
<?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
    }
?>

In title.php, you need to modify the link to pass the post_id as a parameter so that you can retrieve the specific comments for that post:

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
    }
?>

With these modifications, when you click on a post from the title.php page, it will pass the post_id to the home.php page and only display the comments for that specific post.
 
Based on your code, it looks like you are trying to display the content and comments for each post on the home.php page. However, when you click on a specific post from the title.php page, it only displays the latest comment for all posts instead of the comments specific to that post.

To fix this issue, you need to modify your code in home.php and title.php to ensure that only the comments for the selected post are displayed.

In home.php, you should modify the code for displaying comments to only fetch the comments for the current post:

PHP:
<?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
    }
?>

In title.php, you need to modify the link to pass the post_id as a parameter so that you can retrieve the specific comments for that post:

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
    }
?>

With these modifications, when you click on a post from the title.php page, it will pass the post_id to the home.php page and only display the comments for that specific post.
wala pa rin po effect di po gumana
 
wala pa rin po effect di po gumana
I apologize for the confusion. Upon reviewing your code, I noticed a few areas that might be causing the issue. Here are the suggested modifications:

In home.php, modify the code for the comment section to include the post_id as a hidden input field within the form:

```php
<form method="post">
<hr>
Comment:<br>
<input
 
I apologize for the confusion. Upon reviewing your code, I noticed a few areas that might be causing the issue. Here are the suggested modifications:

In home.php, modify the code for the comment section to include the post_id as a hidden input field within the form:

```php
<form method="post">
<hr>
Comment:<br>
<input
nakita ko na po kapag clinilick ko yun title ng content lumabas is yun same na content
 
nakita ko na po kapag clinilick ko yun title ng content lumabas is yun same na content
I apologize for the confusion. Here are the suggested modifications:

In title.php, modify the link to pass the post_id as a parameter:

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
    }
?>

In home.php, modify the code for retrieving the post_id from the URL parameter and display only the comments for that specific post:

```php
<?php
// Retrieve the post_id from the URL parameter
$id = $_GET['id'];

// Fetch the post details based on the post_id
$post_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'") or die(mysqli_error());
$post_row = mysqli_fetch_array($post_query);

// Display the post details
$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 *
 
I apologize for the confusion. Here are the suggested modifications:

In title.php, modify the link to pass the post_id as a parameter:

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
    }
?>

In home.php, modify the code for retrieving the post_id from the URL parameter and display only the comments for that specific post:

```php
<?php
// Retrieve the post_id from the URL parameter
$id = $_GET['id'];

// Fetch the post details based on the post_id
$post_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'") or die(mysqli_error());
$post_row = mysqli_fetch_array($post_query);

// Display the post details
$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 *
Warning: Undefined array key "id" in C:\xampp\htdocs\post_and_comment_system\home.php on line 34

yan po naging error nya
 

Similar threads

Back
Top