Ganito error pano mafix

loktoy

Established
Fatal error: Uncaught TypeError: mysqli_fetch_array(): Argument #2 ($mode) must be of type int, mysqli_result given in C:\xampp\htdocs\Innerjoin\user\dashboard.php:95 Stack trace: #0 C:\xampp\htdocs\Innerjoin\user\dashboard.php(95): mysqli_fetch_array(Object(mysqli_result), Object(mysqli_result)) #1 {main} thrown in C:\xampp\htdocs\Innerjoin\user\dashboard.php on line 95

$sql = mysqli_query($con, "SELECT *, UNIX_TIMESTAMP() - date_created AS TimeSpent FROM post inner join registration on registration.user_id = post.user_id") or die (mysqli_error());
$sql_query = mysqli_query($con, "SELECT *, UNIX_TIMESTAMP() - date_posted AS TimeSpent FROM comment inner join registration on registration.user_id = comment.user_id") or die (mysqli_error());
while($post_row = mysqli_fetch_array($sql,$sql_query)){
$id_user = $post_row['username'];
$id_comment = $post_row ['comment_id'];
?>
<hr>

<div class="">
<?php echo $id_user;?><a href="postinsert1.php?id=<?php echo $id_comment;?>"><?php echo $post_row['title']; ?></a>
 
The error message you encountered is related to the usage of the mysqli_fetch_array() function. The mysqli_fetch_array() function is used to fetch a result row as an associative array, a numeric array, or both from a result set.

In your code, you are passing two arguments to the mysqli_fetch_array() function: $sql and $sql_query. However, the second argument, $mode, should be an integer representing the desired result type.

To fix the error, you should modify your code to fetch the result rows separately for each query. Here's an updated version of your code:

PHP:
$sql = mysqli_query($con, "SELECT *, UNIX_TIMESTAMP() - date_created AS TimeSpent FROM post inner join registration on registration.user_id = post.user_id") or die (mysqli_error());
while($post_row = mysqli_fetch_array($sql)){
    $id_user = $post_row['username'];
    $id_comment = $post_row ['comment_id'];
    ?>
    <hr>
    <div class="">
    <?php echo $id_user;?><a href="postinsert1.php?id=<?php echo $id_comment;?>"><?php echo $post_row['title']; ?></a>
    </div>
<?php
}

$sql_query = mysqli_query($con, "SELECT *, UNIX_TIMESTAMP() - date_posted AS TimeSpent FROM comment inner join registration on registration.user_id = comment.user_id") or die (mysqli_error());
while($comment_row = mysqli_fetch_array($sql_query)){
    // Handle comment data here
    // ...
}

By separating the mysqli_fetch_array() calls and using the correct result sets, the error should be resolved.
 

About this Thread

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

Trending Topics

Online now

Members online
636
Guests online
1,260
Total visitors
1,896

Forum statistics

Threads
2,274,093
Posts
28,953,635
Members
1,235,063
Latest member
papapipzvlog
Back
Top