DrNawaf
DrNawaf

Reputation: 1

Php Mysql echo only half of the results and sometimes none

I am trying to echo username.I have a table in which i only have USERID and then i take that USEDID and compare it in another table and ECHO USERNAME from there.But if there are 50 entries then it only echoes 25 .

here is the code

<?php while($row = mysqli_fetch_assoc($result)) {
$user_id = $row['user_id'];
$result2 = mysqli_query($conn, "select * from `users` WHERE `user_id` = '$user_id'");
$row2 = mysqli_fetch_assoc($result2);
while($row2 = mysqli_fetch_assoc($result2)){
$username = $row2['username'];
}
 ?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['user_id']; ?></td>
<td><?php echo $username; ?></td>
<td><?php echo $row['points']; ?></td>
</tr>

This above code doesnt echo anything at all in username but echo all results

If i change

$row2 = mysqli_fetch_assoc($result2);

to

$row2 = mysqli_fetch_assoc($result);

It echo everything with username but only few/half results

Other code that is in connection with this

$result = mysqli_query($conn, "select * from `lottery`");
    $row = mysqli_fetch_assoc($result); 

Upvotes: 0

Views: 50

Answers (1)

raidenace
raidenace

Reputation: 12836

Remove this line:

$row2 = mysqli_fetch_assoc($result2)

Upvotes: 1

Related Questions