[Solved] While Loop in php not working properly [closed]


Your loop isn’t printing anything to the page. It’s setting values to variables. And it’s over-writing those variable every time. So when the loop is done, only the last values are still set.

Then you just echo that last value. Once.

Instead, echo the output inside the loop so you can have one element of output for each loop iteration:

while ($rows = mysql_fetch_array($fetch))
{
    $ID=$rows['id'];
    $User=$rows['user'];
    $Password=$rows['password'];

    echo "<tr> 
    <td>$ID</td>
    <td>$User</td>
    <td>$Password</td>
    </tr>";
}

Note, however, that there are a couple of other things wrong here:

  1. Your code is vulnerable to XSS attacks.
  2. You are displaying user passwords. Never, ever do that. Your system shouldn’t even have user passwords in a readable format. User passwords should be obscured using a 1-way hash and should never be retrievable by anybody.

2

solved While Loop in php not working properly [closed]