What's new

Pano ko kaya to marereplace

loktoy

Eternal Poster
Joined
Oct 20, 2014
Posts
1,168
Solutions
2
Reaction
103
Points
497
Age
30
gusto ko kapag click ko tong code na to

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 (mysqli_num_rows($content_query) > 0) {
// Code to display the content
echo '<div class="container col-md-6 bg-body-tertiary border rounded-3">'.$content_row['comment'].'</div>';
} else {
// Code to handle when no content is found
}

}
?>

marereplace nya itong code na to

<?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.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="mb-3">
<?php echo $comment_row['comment'];
?>
</div>


yun dalawang echo
 
To replace the two echo statements in the code, you can use the following code:

PHP:
<?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.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="mb-3">
    <?php echo $comment_row['comment']; ?>
</div>

<?php } ?>

Replace the two lines starting with <?php echo $comment_row['comment']; ?> with the desired code that you want to display for each comment.
 
To replace the two echo statements in the code, you can use the following code:

PHP:
<?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.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="mb-3">
    <?php echo $comment_row['comment']; ?>
</div>

<?php } ?>

Replace the two lines starting with <?php echo $comment_row['comment']; ?> with the desired code that you want to display for each comment.
mali pala ito pala code na to gusto kong gawin dapat nag papalitan yun dalawan echo na
ito

echo '<div class="container col-md-6 bg-body-tertiary border rounded-3">'.$content_row['comment'].'</div>';
at
h6><?php echo $post_row['comment'];?></h6>

ito code ko sa unang isset

<?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 (mysqli_num_rows($content_query) > 0) {
// Code to display the content
echo '<div class="container col-md-6 bg-body-tertiary border rounded-3">'.$content_row['comment'].'</div>';
} else {
// Code to handle when no content is found
}

}
?>

ito yun pangalawa isset
if (isset($_POST['post'])){
$page_content = mysqli_real_escape_string($con,$_POST ['post_content']);
$pagecontent = mysqli_real_escape_string($con,$_POST ['postcontent']);



mysqli_query($con,"INSERT INTO post (comment,title,date_created,user_id) values ('$page_content','$pagecontent','".strtotime(date("Y-m-d h:i:sa"))."','$user_id') ")or die(mysqli_error());

}
?>
<?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'];
?>
<h6><?php echo $post_row['comment'];?></h6>
 
mali pala ito pala code na to gusto kong gawin dapat nag papalitan yun dalawan echo na
ito

echo '<div class="container col-md-6 bg-body-tertiary border rounded-3">'.$content_row['comment'].'</div>';
at
h6><?php echo $post_row['comment'];?></h6>

ito code ko sa unang isset

<?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 (mysqli_num_rows($content_query) > 0) {
// Code to display the content
echo '<div class="container col-md-6 bg-body-tertiary border rounded-3">'.$content_row['comment'].'</div>';
} else {
// Code to handle when no content is found
}

}
?>

ito yun pangalawa isset
if (isset($_POST['post'])){
$page_content = mysqli_real_escape_string($con,$_POST ['post_content']);
$pagecontent = mysqli_real_escape_string($con,$_POST ['postcontent']);



mysqli_query($con,"INSERT INTO post (comment,title,date_created,user_id) values ('$page_content','$pagecontent','".strtotime(date("Y-m-d h:i:sa"))."','$user_id') ")or die(mysqli_error());

}
?>
<?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'];
?>
<h6><?php echo $post_row['comment'];?></h6>
To replace the echo statements in the code, you can use the following code:

For the first isset section:

PHP:
<?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 (mysqli_num_rows($content_query) > 0) {
        // Code to display the content  
        echo '<div class="container col-md-6 bg-body-tertiary border rounded-3">'.$content_row['comment'].'</div>';
    } else {
        // Code to handle when no content is found
    }
}
?>

Replace the line starting with echo '<div class="container col-md-6 bg-body-tertiary border rounded-3">'.$content_row['comment'].'</div>'; with your desired code.

For the second isset section:

PHP:
<?php
if (isset($_POST['post'])){
    $page_content = mysqli_real_escape_string($con,$_POST ['post_content']);
    $pagecontent = mysqli_real_escape_string($con,$_POST ['postcontent']);
    
    mysqli_query($con,"INSERT INTO post (comment,title,date_created,user_id) values ('$page_content','$pagecontent','".strtotime(date("Y-m-d h:i:sa"))."','$user_id') ")or die(mysqli_error());
}
?>

<?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'];
?>
<h6><?php echo $post_row['comment'];?></h6>
<?php } ?>

Replace the line starting with <h6><?php echo $post_row['comment'];?></h6> with your desired code.
 
To replace the echo statements in the code, you can use the following code:

For the first isset section:

PHP:
<?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 (mysqli_num_rows($content_query) > 0) {
        // Code to display the content 
        echo '<div class="container col-md-6 bg-body-tertiary border rounded-3">'.$content_row['comment'].'</div>';
    } else {
        // Code to handle when no content is found
    }
}
?>

Replace the line starting with echo '<div class="container col-md-6 bg-body-tertiary border rounded-3">'.$content_row['comment'].'</div>'; with your desired code.

For the second isset section:

PHP:
<?php
if (isset($_POST['post'])){
    $page_content = mysqli_real_escape_string($con,$_POST ['post_content']);
    $pagecontent = mysqli_real_escape_string($con,$_POST ['postcontent']);
   
    mysqli_query($con,"INSERT INTO post (comment,title,date_created,user_id) values ('$page_content','$pagecontent','".strtotime(date("Y-m-d h:i:sa"))."','$user_id') ")or die(mysqli_error());
}
?>

<?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'];
?>
<h6><?php echo $post_row['comment'];?></h6>
<?php } ?>

Replace the line starting with <h6><?php echo $post_row['comment'];?></h6> with your desired code.
di po gusto ko po mangyari is yun isa magiging visible at yun isa hide then alternate kung sakali alin gusto ko pindutin magiging visible yun isa yun isa hide
 
di po gusto ko po mangyari is yun isa magiging visible at yun isa hide then alternate kung sakali alin gusto ko pindutin magiging visible yun isa yun isa hide
To achieve the desired functionality where one element is visible while the other is hidden, and they alternate visibility when clicked, you can use JavaScript/jQuery along with some modifications to your code. Here's an example implementation:

First, include the jQuery library in your HTML file:

HTML:
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

Then, modify your code as follows:

For the first isset section:

PHP:
<?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 (mysqli_num_rows($content_query) > 0) {
        // Code to display the content
        echo '<div class="container col-md-6 bg-body-tertiary border rounded-3" id="content1">'.$content_row['comment'].'</div>';
        echo '<div class="container col-md-6 bg-body-tertiary border rounded-3" id="content2" style="display: none;">'.$content_row['comment'].'</div>';
    } else {
        // Code to handle when no content is found
    }
}
?>

For the second isset section:

PHP:
<?php
if (isset($_POST['post'])){
    $page_content = mysqli_real_escape_string($con,$_POST ['post_content']);
    $pagecontent = mysqli_real_escape_string($con,$_POST ['postcontent']);

    mysqli_query($con,"INSERT INTO post (comment,title,date_created,user_id) values ('$page_content','$pagecontent','".strtotime(date("Y-m-d h:i:sa"))."','$user_id') ")or die(mysqli_error());
}
?>

<script>
$(document).ready(function(){
    $("#content1").click(function(){
        $("#content1").hide();
        $("#content2").show();
    });
    
    $("#content2").click(function(){
        $("#content2").hide();
        $("#content1").show();
    });
});
</script>

In this code, we added unique IDs (content1 and content2) to the two div elements that you want to alternate visibility. Initially, content1 is visible while content2 is hidden. When content1 is clicked, it hides content1 and shows content2. When content2 is clicked, it hides content2 and shows content1.

Note: Make sure to place the JavaScript code within <script></script> tags and wrap it inside the $(document).ready() function to ensure that it executes after the HTML elements are fully loaded.

Remember to adjust the code according to your specific implementation and styling needs.
 

Similar threads

Back
Top