How can I display the results of mysql_fetch_assoc in a dynamic table? I have a MySQL database with several columns and two rows of data, so far. I'm using mysql_fetch_assoc to return the data in database, but I don't know how to put it all together in a table so that I can display it in another file.

Here is the code of the file that does the process (query.php):

&lt;?php

// Configure connection settings

$db = 'scorecard';
$db_admin = 'root';
$db_password = '********';
$tablename = 'scoreboard';

// Title

//echo "&lt;b&gt;DIV!&lt;/b&gt;";

// Connect to DB

$sql = mysql_connect("localhost", $db_admin, $db_password)
or die(mysql_error());

mysql_select_db("$db", $sql);

// Fetch the data

$query = "SELECT * FROM $tablename";
$result = mysql_query($query);
echo mysql_error();

echo "&lt;table width='100%'&gt;\n";
echo "&lt;tr&gt;\n";

// Return the results, loop through them and echo

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$codcliente = $row['codcliente'];
$nombre = $row['nombre'];
$ejecutivo = $row['ejecutivo'];
$banca_as400 = $row['banca_as400'];
$banca_real = $row['banca_real'];
$ingresos = $row['ingresos'];
$ciiu = $row['ciiu'];
$division = $row['division'];
$actividad = $row['actividad'];
$riesgo_industria = $row['riesgo_industria'];
$riesgo_cliente = $row['riesgo_cliente'];
$fecha = $row['fecha'];
$analista = $row['analista'];
echo "&lt;tr&gt;&lt;td&gt;$codcliente&lt;/td&gt;&lt;td&gt;$nombre&lt;/td&gt;&lt;td&gt;$ejecutivo&lt;/td&gt;&lt;td&gt;$banca_as400&lt;/td&gt;&lt;td&gt;$banca_real&lt;/td&gt;&lt;td&gt;$ingresos&lt;/td&gt;&lt;td&gt;$ciiu&lt;/td&gt;&lt;td&gt;$division&lt;/td&gt;&lt;td&gt;$actividad&lt;/td&gt;&lt;td&gt;$riesgo_industria&lt;/td&gt;&lt;td&gt;$riesgo_cliente&lt;/td&gt;&lt;td&gt;$fecha&lt;/td&gt;&lt;td&gt;$analista&lt;/td&gt;&lt;/tr&gt;\n";
echo "&lt;tr&gt;&lt;td&gt;$codcliente&lt;/td&gt;&lt;td&gt;$nombre&lt;/td&gt;&lt;td&gt;$ejecutivo&lt;/td&gt;&lt;td&gt;$banca_as400&lt;/td&gt;&lt;td&gt;$banca_real&lt;/td&gt;&lt;td&gt;$ingresos&lt;/td&gt;&lt;td&gt;$ciiu&lt;/td&gt;&lt;td&gt;$division&lt;/td&gt;&lt;td&gt;$actividad&lt;/td&gt;&lt;td&gt;$riesgo_industria&lt;/td&gt;&lt;td&gt;$riesgo_cliente&lt;/td&gt;&lt;td&gt;$fecha&lt;/td&gt;&lt;td&gt;$analista&lt;/td&gt;&lt;/tr&gt;\n";
echo "&lt;/table&gt;\n";
}


And this is the result from the page that displays the process (index.php):

CAN'T DISPLAY SINCE I DON'T HAVE ENOUGH REPUTATION POINTS :(

As you can see, I have a table already in place and I would like the results to fall below as additional rows, but they come out all squashed together. I've tried several mysql_fetch types, but nothing works. The query results are displayed in a JavaScript DIV that is automatically refreshed by an AJAX script from another file (ajax.js). If you need to see the code for index.php or ajax.js, I could provide it.

Thanks!
Aren't you forgetting something, called &lt;td&gt;?

Try

&lt;?php

// Configure connection settings

$db = 'scorecard';
$db_admin = 'root';
$db_password = '********';
$tablename = 'scoreboard';

// Title

//echo "&lt;b&gt;DIV!&lt;/b&gt;";

// Connect to DB

$sql = mysql_connect("localhost", $db_admin, $db_password)
or die(mysql_error());

mysql_select_db("$db", $sql);

// Fetch the data

$query = "SELECT * FROM $tablename";
$result = mysql_query($query);
echo mysql_error();

echo "&lt;table width='100%'&gt;\n";

// Return the results, loop through them and echo

while($row = mysql_fetch_assoc($result))
{
    echo '&lt;tr&gt;'."\n";
    echo "&lt;td&gt;{$row['codcliente']}&lt;/td&gt;\n" . "&lt;td&gt;{$row['nombre']}&lt;/td&gt;\n" . "&lt;td&gt;{$row['ejecutivo']}&lt;/td&gt;\n" . "&lt;td&gt;{$row['banca_as400']}&lt;/td&gt;\n" . "&lt;td&gt;{$row['banca_real']}&lt;/td&gt;\n" . "&lt;td&gt;{$row['ingresos']}&lt;/td&gt;\n" . "&lt;td&gt;{$row['ciiu']}&lt;/td&gt;\n" . "&lt;td&gt;{$row['division']}&lt;/td&gt;\n" . "&lt;td&gt;{$row['actividad']}&lt;/td&gt;\n" . "&lt;td&gt;{$row['riesgo_industria']}&lt;/td&gt;\n" . "&lt;td&gt;{$row['riesgo_cliente']}&lt;/td&gt;\n" . "&lt;td&gt;{$row['fecha']}&lt;/td&gt;\n" . "&lt;td&gt;{$row['analista']}&lt;/td&gt;\n";

    echo '&lt;/tr&gt;'."\n";
}

echo "&lt;/table&gt;\n";

?&gt;