🔒 Closed Ganito error pano mafix

Status
Not open for further replies.

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.
 
Status
Not open for further replies.

About this Thread

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

Trending Topics

Online now

Members online
1,179
Guests online
3,248
Total visitors
4,427

Forum statistics

Threads
2,307,404
Posts
29,178,802
Members
1,193,397
Latest member
aung htut
Back
Top