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
):
<?php
// Configure connection settings
$db = 'scorecard';
$db_admin = 'root';
$db_password = '********';
$tablename = 'scoreboard';
// Title
//echo "<b>DIV!</b>";
// 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 "<table width='100%'>\n";
echo "<tr>\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 "<tr><td>$codcliente</td><td>$nombre</td><td>$ejecutivo</td><td>$banca_as400</td><td>$banca_real</td><td>$ingresos</td><td>$ciiu</td><td>$division</td><td>$actividad</td><td>$riesgo_industria</td><td>$riesgo_cliente</td><td>$fecha</td><td>$analista</td></tr>\n";
echo "<tr><td>$codcliente</td><td>$nombre</td><td>$ejecutivo</td><td>$banca_as400</td><td>$banca_real</td><td>$ingresos</td><td>$ciiu</td><td>$division</td><td>$actividad</td><td>$riesgo_industria</td><td>$riesgo_cliente</td><td>$fecha</td><td>$analista</td></tr>\n";
echo "</table>\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!