tags:

views:

61

answers:

3

Here is te code:

<?php

//Starting session

session_start();

//Includes mass includes containing all the files needed to execute the full script
//Also shows homepage elements without customs

require_once ('includes/mass.php');

$username = $_SESSION['username'];

if (isset($username))

{   

//Query database for the users networths

$sq_l = "SELECT * FROM user";

$sql_query_worth = mysql_query($sq_l);

while ($row = mysql_fetch_assoc($sql_query_worth))

      {

         $dbusername = $row['username'];


      } 

      echo $dbusername;

}
?>
+10  A: 

You're echoing outside of the loop. So it's only echoing the last row. Put that echo statement inside your while loop.

Tesserex
Thank You. Was a silly mistake.
Tapha
+2  A: 

If you want to print all usernames, then the echo statement should be within the while loop, eg.

while ($row = mysql_fetch_assoc($sql_query_worth))
  {
    $dbusername = $row['username'];
    echo $dbusername;
  }
ar
+2  A: 

You are using this portion of code :

while ($row = mysql_fetch_assoc($sql_query_worth))
{
     $dbusername = $row['username'];
} 

echo $dbusername;

Which means only the name of the last user will be echoed :

  • On each iteration of the loop, the username is stored in $dbusername
  • But that variable's content is only echoed aftezr the loop
    • which means only the last value of $row['username'] will be echoed.


If you want to output each usename, you shoud put the echo inside the loop, and not after :

while ($row = mysql_fetch_assoc($sql_query_worth))
{
    $dbusername = $row['username'];
    echo $dbusername . '<br />';
} 

And, with that, each name of each user should be echoed ;-)

Pascal MARTIN