What's new

Phc robot

loktoy

Eternal Poster
Joined
Oct 20, 2014
Posts
1,168
Solutions
2
Reaction
103
Points
497
Age
30
ito problima ko po kapag kapag pinipindot ko yun title sa title.php lumabas yun naka assign sa kanya content ngaun yun problima po is yun reply nila pareparehas sa bawat content lumalabas gusto ko po mangyari is kung wala reply sa isang content wala rin lalabas kung dalawa lang nag reply dapat dalawa lang magpakita kaso lahat ng reply ay nagpapakita sa bawat content..

ito code sa replies.php

<?php
ob_start();
include "../partials/newnav.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 text-center">
<br>
<h1>WELCOME To My Thread!</h1>

<br>

<br>
</div>
<?php
if(isset($_GET['id'])){
$id_comment = $_GET['id'];
// Query to fetch the specific content based on the comment_id
$content_query = mysqli_query($con, "SELECT * FROM post WHERE comment_id = '$id_comment'") or die(mysqli_error());
$content_row = mysqli_fetch_array($content_query);


?>
<h6><?php echo $content_row['comment']; ?></h6>
<?php
$post_query = mysqli_query($con, "SELECT *, UNIX_TIMESTAMP() - date_created AS TimeSpent FROM post LEFT JOIN registration on registration.user_id = post.user_id ORDER BY comment_id DESC limit 1 ") or die (mysqli_error());
while($post_row = mysqli_fetch_array($post_query)){
$id = $post_row['comment_id'];
$upid = $post_row['user_id'];
$posted_by = $post_row['username'];
?>
<br>
<form method="post">

<div class="container col-md-6">
Comment:<br>
<input type="hidden" name="id" value="<?php echo $id; ?>">
<textarea name="comment_content" class="form-control" rows="4" cols="50" style="" placeholder=".........Type your comment here........" required></textarea>
<div class="form-group mt-2">
<input class="w-25" type="submit" name="comment" value ="Reply" style="background-color:#0D52C7;">
</div>
</div>
</form>

</br>
<?php

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

mysqli_query($con,"insert into comment (comment,date_posted,user_id,comment_id) values ('$comment_content','".strtotime(date("Y-m-d h:i:sa"))."','$user_id','$post_id')") or die (mysqli_error());
header('Location: comment.php');
exit();
ob_end_flush();}
?>

<?php
$comment_query = mysqli_query($con,"SELECT DISTINCT DISTINCT * ,UNIX_TIMESTAMP() - date_posted AS TimeSpent FROM comment inner JOIN registration on registration.user_id = comment.user_id where comment_id = '$id' order by date_posted DESC") or die (mysqli_error());
while ($comment_row=mysqli_fetch_array($comment_query)){
$comment_id = $comment_row['id'];
$comment_by = $comment_row['username'];
?>
<div class="container col-md-6 bg-body-tertiary border rounded-3">
Comment by: <a href="#" style= "margin-left:10px; text-decoration:none;"> <?php echo $comment_by; ?></a>
<div class="" style="font-size:12px;">
<?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';
?>
<img src ="../images/hour.png" alt = "My hour" style ="width:12px;">
</div>


<div class="mb-3">
<?php echo $comment_row['comment']; ?>
</div>
</div>

<br>

<?php
}}}?>


<hr>

<?php
include "../partials/footer.php";
?>


</body>
</html>

ito nman sa title.php
<?php
$sql = mysqli_query($con, "SELECT * ,UNIX_TIMESTAMP() - date_created AS TimeSpent FROM post left join registration on registration.user_id = post.user_id order by date_created DESC" ) or die (mysqli_error());
while($post_row = mysqli_fetch_array($sql)){
$id_user = $post_row['username'];
$id_comment = $post_row ['comment_id'];
?>
</div>
<div class ="container col-md-6 bg-body-tertiary">
<a href="replies.php?id=<?php echo $id_comment;?>"><?php echo $post_row['title']; ?></a>
<br>
<!-- <div class="" style="font-size:12px;"> -->
<?php }?>
 
Based on the code you provided, it seems like the issue lies in the query used to fetch comments in the replies.php file. Currently, you are fetching all comments for a specific content regardless of the content's ID.

To fix this issue and only display the comments that are related to a specific content, you need to modify the SQL query in the replies.php file. Instead of fetching all comments, you should only fetch comments that have the same comment_id as the content you are currently viewing.

Replace this line of code:

PHP:
$comment_query = mysqli_query($con,"SELECT DISTINCT DISTINCT * ,UNIX_TIMESTAMP() - date_posted AS TimeSpent FROM comment inner JOIN registration on registration.user_id = comment.user_id where comment_id = '$id' order by date_posted DESC") or die (mysqli_error());

With this modified line of code:

PHP:
$comment_query = mysqli_query($con,"SELECT DISTINCT DISTINCT * ,UNIX_TIMESTAMP() - date_posted AS TimeSpent FROM comment INNER JOIN registration ON registration.user_id = comment.user_id INNER JOIN post ON comment.comment_id = post.comment_id WHERE post.comment_id = '$id' ORDER BY date_posted DESC") or die (mysqli_error());

This query joins the comment table with the registration table and the post table. It only selects comments that have the same comment_id as the content you are currently viewing ($id). This should ensure that only comments related to the specific content are displayed.

Make sure to save the changes and test the functionality again. The comments should now only be displayed for the specific content you are viewing.
 
Based on the code you provided, it seems like the issue lies in the query used to fetch comments in the replies.php file. Currently, you are fetching all comments for a specific content regardless of the content's ID.

To fix this issue and only display the comments that are related to a specific content, you need to modify the SQL query in the replies.php file. Instead of fetching all comments, you should only fetch comments that have the same comment_id as the content you are currently viewing.

Replace this line of code:

PHP:
$comment_query = mysqli_query($con,"SELECT DISTINCT DISTINCT * ,UNIX_TIMESTAMP() - date_posted AS TimeSpent FROM comment inner JOIN registration on registration.user_id = comment.user_id where comment_id = '$id' order by date_posted DESC") or die (mysqli_error());

With this modified line of code:

PHP:
$comment_query = mysqli_query($con,"SELECT DISTINCT DISTINCT * ,UNIX_TIMESTAMP() - date_posted AS TimeSpent FROM comment INNER JOIN registration ON registration.user_id = comment.user_id INNER JOIN post ON comment.comment_id = post.comment_id WHERE post.comment_id = '$id' ORDER BY date_posted DESC") or die (mysqli_error());

This query joins the comment table with the registration table and the post table. It only selects comments that have the same comment_id as the content you are currently viewing ($id). This should ensure that only comments related to the specific content are displayed.

Make sure to save the changes and test the functionality again. The comments should now only be displayed for the specific content you are viewing.
same pa rin yun issue
 
same pa rin yun issue
Apologies for the confusion. Upon further review, it seems that the issue lies in the way you are displaying the comments in the replies.php file. Currently, you are using a while loop to fetch and display all comments, which results in displaying all comments for every content.

To resolve this issue and only display the relevant comments for each content, you need to modify the code structure. You can use a nested loop to fetch and display comments only for the specific content you are viewing.

Here's the updated code for the replies.php file:

PHP:
<?php
ob_start();
include "../partials/newnav.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 text-center">
    <br>
    <h1>WELCOME To My Thread!</h1>
    <br>
</div>

<?php
if(isset($_GET['id'])) {
    $id_comment = $_GET['id'];

    // Query to fetch the specific content based on the comment_id
    $content_query = mysqli_query($con, "SELECT * FROM post WHERE comment_id = '$id_comment'") or die(mysqli_error());
    $content_row = mysqli_fetch_array($content_query);
    
    if ($content_row) {
        // Display the content
        echo '<h6>' . $content_row['comment'] . '</h6>';
        
        // Fetch and display the comments for the specific content
        $comment_query = mysqli_query($con, "SELECT *, UNIX_TIMESTAMP() - date_posted AS TimeSpent FROM comment INNER JOIN registration ON registration.user_id = comment.user_id WHERE comment.comment_id = '$id_comment' ORDER BY date_posted DESC") or die(mysqli_error());

        while ($comment_row = mysqli_fetch_array($comment_query)) {
            $comment_id = $comment_row['id'];
            $comment_by = $comment_row['username'];
            ?>

            <div class="container col-md-6 bg-body-tertiary border rounded-3">
                Comment by: <a href="#" style="margin-left: 10px; text-decoration: none;"><?php echo $comment_by; ?></a>
                <div class="" style="font-size: 12px;">
                    <?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';
                    ?>
                    <img src="../images/hour.png" alt="My hour" style="width:12px;">
                </div>

                <div class="mb-3">
                    <?php echo $comment_row['comment']; ?>
                </div>
            </div>

            <br>

            <?php
        }
    } else {
        echo "No content found for the given ID.";
    }
}
?>

<?php
include "../partials/footer.php";
?>

</body>
</html>

In the updated code, I have added an if condition to check if the content exists for the given ID. If it exists, the content is displayed along with its associated comments. Otherwise, a message is displayed indicating that no content was found for the given ID.

Please make sure to save the changes and test the functionality again. The comments should now only be displayed for the specific content you are viewing.
 
Apologies for the confusion. Upon further review, it seems that the issue lies in the way you are displaying the comments in the replies.php file. Currently, you are using a while loop to fetch and display all comments, which results in displaying all comments for every content.

To resolve this issue and only display the relevant comments for each content, you need to modify the code structure. You can use a nested loop to fetch and display comments only for the specific content you are viewing.

Here's the updated code for the replies.php file:

PHP:
<?php
ob_start();
include "../partials/newnav.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 text-center">
    <br>
    <h1>WELCOME To My Thread!</h1>
    <br>
</div>

<?php
if(isset($_GET['id'])) {
    $id_comment = $_GET['id'];

    // Query to fetch the specific content based on the comment_id
    $content_query = mysqli_query($con, "SELECT * FROM post WHERE comment_id = '$id_comment'") or die(mysqli_error());
    $content_row = mysqli_fetch_array($content_query);
   
    if ($content_row) {
        // Display the content
        echo '<h6>' . $content_row['comment'] . '</h6>';
       
        // Fetch and display the comments for the specific content
        $comment_query = mysqli_query($con, "SELECT *, UNIX_TIMESTAMP() - date_posted AS TimeSpent FROM comment INNER JOIN registration ON registration.user_id = comment.user_id WHERE comment.comment_id = '$id_comment' ORDER BY date_posted DESC") or die(mysqli_error());

        while ($comment_row = mysqli_fetch_array($comment_query)) {
            $comment_id = $comment_row['id'];
            $comment_by = $comment_row['username'];
            ?>

            <div class="container col-md-6 bg-body-tertiary border rounded-3">
                Comment by: <a href="#" style="margin-left: 10px; text-decoration: none;"><?php echo $comment_by; ?></a>
                <div class="" style="font-size: 12px;">
                    <?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';
                    ?>
                    <img src="../images/hour.png" alt="My hour" style="width:12px;">
                </div>

                <div class="mb-3">
                    <?php echo $comment_row['comment']; ?>
                </div>
            </div>

            <br>

            <?php
        }
    } else {
        echo "No content found for the given ID.";
    }
}
?>

<?php
include "../partials/footer.php";
?>

</body>
</html>

In the updated code, I have added an if condition to check if the content exists for the given ID. If it exists, the content is displayed along with its associated comments. Otherwise, a message is displayed indicating that no content was found for the given ID.

Please make sure to save the changes and test the functionality again. The comments should now only be displayed for the specific content you are viewing.
ok na po sya nag oouput na po sya ng reply o comment sa kanya content ang problima ko po is kapag nireload ko sya meron pa rin po nag papakita reply o comment na di dpat sakanya..ibig sabihin po may naliligaw na reply o comment

ok na po sya nag oouput na po sya ng reply o comment sa kanya content ang problima ko po is kapag nireload ko sya meron pa rin po nag papakita reply o comment na di dpat sakanya..ibig sabihin po may naliligaw na reply o comment
ito po code ko
<?php
ob_start();
include "../partials/newnav.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 text-center">
<br>
<h1>WELCOME To My Thread!</h1>

<br>

<br>
</div>
<?php
if(isset($_GET['id'])){
$id_comment = $_GET['id'];
// Query to fetch the specific content based on the comment_id
$content_query = mysqli_query($con, "SELECT * FROM post WHERE comment_id = '$id_comment'") or die(mysqli_error());
$content_row = mysqli_fetch_array($content_query);


?>
<h6><?php echo $content_row['comment']; ?></h6>
<?php
$post_query = mysqli_query($con, "SELECT *, UNIX_TIMESTAMP() - date_created AS TimeSpent FROM post LEFT JOIN registration on registration.user_id = post.user_id ORDER BY comment_id DESC limit 1 ") or die (mysqli_error());
while($post_row = mysqli_fetch_array($post_query)){
$id = $post_row['comment_id'];
$upid = $post_row['user_id'];
$posted_by = $post_row['username'];
?>
<br>
<form method="post">

<div class="container col-md-6">
Comment:<br>
<input type="hidden" name="id" value="<?php echo $id; ?>">
<textarea name="comment_content" class="form-control" rows="4" cols="50" style="" placeholder=".........Type your comment here........" required></textarea>
<div class="form-group mt-2">
<input class="w-25" type="submit" name="comment" value ="Reply" style="background-color:#0D52C7;">
</div>
</div>
</form>

</br>
<?php

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

mysqli_query($con,"insert into comment (comment,date_posted,user_id,comment_id) values ('$comment_content','".strtotime(date("Y-m-d h:i:sa"))."','$user_id','$post_id')") or die (mysqli_error());
header('Location: comment.php');
exit();
ob_end_flush();}
?>

<?php
$comment_query = mysqli_query($con, "SELECT *, UNIX_TIMESTAMP() - date_posted AS TimeSpent FROM comment INNER JOIN registration ON registration.user_id = comment.user_id WHERE comment.comment_id = '$id_comment' ORDER BY date_posted DESC") or die(mysqli_error());
while ($comment_row=mysqli_fetch_array($comment_query)){
$comment_id = $comment_row['id'];
$comment_by = $comment_row['username'];
?>
<div class="container col-md-6 bg-body-tertiary border rounded-3">
Comment by: <a href="#" style= "margin-left:10px; text-decoration:none;"> <?php echo $comment_by; ?></a>
<div class="" style="font-size:12px;">
<?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';
?>
<img src ="../images/hour.png" alt = "My hour" style ="width:12px;">
</div>


<div class="mb-3">
<?php echo $comment_row['comment']; ?>
</div>
</div>

<br>


<?php
}}}?>


<hr>

<?php
include "../partials/footer.php";
?>


</body>
</html>
 

Similar threads

Back
Top