What's new

Help clicking on the title takes you directly to the corresponding content?

loktoy

Eternal Poster
Joined
Oct 20, 2014
Posts
1,168
Solutions
2
Reaction
103
Points
497
Age
30
paano kaya to kasi plano ko yun title ay dun nakapaloob yun content ngaun kapg cliclick ko yun title dapat mapupunta sya dun mismo sa content kung anu lang yun title...

ito code ko sa title.php

<?php


$sql = mysqli_query($con, "SELECT * FROM post left join registration on registration.user_id = post.user_id where comment_id = '$id' order by date_created DESC" ) or die (mysqli_error());
while($post_row = mysqli_fetch_array($sql)){
$id = $post_row['comment_id'];
$id_user = $post_row['username'];
$id_comment = $post_row ['comment_id'];
?>
<br><?php echo $username; ?> - <a href="comment.php"><?php echo $post_row['title']; }?></a>

ito naman code ko sa content.php

<h1>WELCOME To My Thread!</h1>


<br>
</div>
<?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'];
?>
<div class="container col-md-6 bg-body-tertiary border rounded-3" >
<a style="text-decoration:none; float:left;" href="deletepost.php<?php echo '?id='.$id; ?>">
<div class="pt-3">
Posted by: <a href="#" style= "margin-left:10px; text-decoration:none;"> <?php echo $posted_by; ?></a>
<div class="" style="font-size:12px;">
<?php
$current_time = time(); // Get the current time
$time_elapsed = $current_time - $post_row['date_created']; // Calculate the time elapsed in seconds
$days = floor($time_elapsed / (60*60*24));
$remainder = $time_elapsed % (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 ($time_elapsed < 60) {
echo "A few seconds ago";
} elseif ($time_elapsed < 3600) { // Less than 1 hour
echo $minutes . ' minutes ago';
} else {
// Handle other cases, such as hours, days, etc.
}
?>
</div>
<br>
<h6><?php echo $post_row['comment']; ?></h6>

</div>
</div>
<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>
 
To achieve the desired functionality where clicking on the title takes you directly to the corresponding content, you need to make a few changes in your code.

In your title.php file, modify the code for the title link as follows:

Code:
<a href="content.php?id=<?php echo $id_comment; ?>"><?php echo $post_row['title']; ?></a>

Here, we are passing the comment_id ($id_comment) as a query parameter in the URL, which will be used to identify the specific content in the content.php file.

Next, in your content.php file, you need to retrieve the comment_id from the URL and use it in your query to fetch the specific content. Modify the code as follows:

Code:
<?php
// Retrieve the comment_id from the URL
$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);
?>

<h1>WELCOME To My Thread!</h1>
<div>
    <br>
    <?php echo $content_row['comment']; ?>
</div>

<!-- Rest of the code -->

With these changes, when you click on the title in the title.php file, it will take you to the content.php file, and the specific content associated with that title will be displayed.
 
To achieve the desired functionality where clicking on the title takes you directly to the corresponding content, you need to make a few changes in your code.

In your title.php file, modify the code for the title link as follows:

Code:
<a href="content.php?id=<?php echo $id_comment; ?>"><?php echo $post_row['title']; ?></a>

Here, we are passing the comment_id ($id_comment) as a query parameter in the URL, which will be used to identify the specific content in the content.php file.

Next, in your content.php file, you need to retrieve the comment_id from the URL and use it in your query to fetch the specific content. Modify the code as follows:

Code:
<?php
// Retrieve the comment_id from the URL
$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);
?>

<h1>WELCOME To My Thread!</h1>
<div>
    <br>
    <?php echo $content_row['comment']; ?>
</div>

<!-- Rest of the code -->

With these changes, when you click on the title in the title.php file, it will take you to the content.php file, and the specific content associated with that title will be displayed.
nawala na po ng display yun title
 
nawala na po ng display yun title
Apologies for the confusion. It seems that the code provided earlier doesn't include the necessary changes to display the title. To fix this issue, you need to modify the code in your content.php file. Here's the updated code:

PHP:
<?php
// Retrieve the comment_id from the URL
$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);
?>

<h1>WELCOME To My Thread!</h1>
<div>
    <br>
    <h3><?php echo $content_row['title']; ?></h3>
    <p><?php echo $content_row['comment']; ?></p>
</div>

<!-- Rest of the code -->

With this updated code, the title associated with the specific content will be displayed on the content.php page.
 

Similar threads

Back
Top