🔒 Closed Paano to pa fix po

Status
Not open for further replies.

loktoy

Established

You do not have permission to view the full content of this post. Log in or register now.


<?php
$slq = mysqli_query($con, "SELECT * FROM post LEFT JOIN registration on registration.user_id = post.user_id ORDER BY comment_id DESC " ) or die (mysqli_error());
while($post_row = mysqli_fetch_array($slq)){
$id = $post_row['comment_id'];
$upid = $post_row['user_id'];
$posted_by = $post_row['username'];
}

?>
<a style="text-decoration:none; float:right;" href="#"><button><font color="red">x</button></font></a>
<h3>Posted by: <a href="#"> <?php echo $posted_by; ?></a>
 
The error message you are encountering is indicating that the variable $posted_by is undefined in your code. This occurs on line 39 of your code, in the file comment.php.

To fix this issue, you need to ensure that the variable $posted_by is defined before attempting to use it on line 39. Looking at your code, you are fetching data from the database using a SELECT statement and storing the results in the $post_row variable within a while loop. However, you are only assigning values to the $posted_by variable within the loop, which means it will only be accessible within the loop.

To resolve this, you can move the line that echoes the $posted_by variable inside the loop, so that it is executed for each iteration of the loop. Here's an updated version of your code that should fix the issue:

PHP:
<?php 
    $slq = mysqli_query($con, "SELECT * FROM post LEFT JOIN registration on registration.user_id = post.user_id ORDER BY comment_id DESC " ) or die (mysqli_error());
    while($post_row = mysqli_fetch_array($slq)){
        $id = $post_row['comment_id'];
        $upid = $post_row['user_id'];
        $posted_by = $post_row['username'];

        // Move the echo statement here, inside the loop
        echo '<a style="text-decoration:none; float:right;" href="#"><button><font  color="red">x</button></font></a>';
        echo '<h3>Posted by: <a href="#">' . $posted_by . '</a></h3>';
    }
?>

By making this change, the $posted_by variable will be defined and accessible within the loop, so you can safely echo its value without encountering any undefined variable errors.
 
Status
Not open for further replies.

About this Thread

  • 1
    Replies
  • 479
    Views
  • 1
    Participants
Last reply from:
Unknown user

Trending Topics

Online now

Members online
1,157
Guests online
1,868
Total visitors
3,025

Forum statistics

Threads
2,295,540
Posts
29,098,758
Members
1,205,929
Latest member
ironman21
Back
Top