Jump to content

Listing Mysql Results in a table?


Deanznet

Recommended Posts

Okay im trying to get a list of mysql tables from a database to get listed into a html table.

 

Im trying to get a 2 column table like below.

 

Table Names  -  Link

Table 1          Click Me link (la.com/ss.php?table=table1)

Table 2          Click Me link (la.com/ss.php?table=table2)

Table 3          Click Me link (la.com/ss.php?table=table3)

 

Someone help me do that please!

 

 

 

 

This is what i got but it doesn't work.

 

       $sql = "SHOW TABLES FROM $db_name";
$result = mysql_query($sql);

if (!$result) {
    echo "DB Error, could not list tables\n";
    echo 'MySQL Error: ' . mysql_error();
    exit;
}

$table = 0;
  while ($table < mysql_num_rows($result))
{

       echo "<tr>\n";
          echo "<td>\n";  echo "{$row[0]}\n";   echo "</td>\n"; 
echo "</tr>\n";
}

mysql_free_result($result);
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/169779-listing-mysql-results-in-a-table/
Share on other sites

Try this, obviously i haven't tested it :-)

 

     $sql = "SHOW TABLES FROM $db_name";
$result = mysql_query($sql);

if (!$result) {
    echo "DB Error, could not list tables\n";
    echo 'MySQL Error: ' . mysql_error();
    exit;
}

echo "<table>";
  while ($row= mysql_fetch_array($result))
{

       echo "<tr>";
          echo "<td>{$row['COLUMN_NAME FROM DATABASE']}</td>"; 
echo "</tr>";
}
echo "</table>";
mysql_free_result($result);
?>

sorry didn't read properly waht you are trying to do. have changed above code slightly to this:

    $sql = "SHOW TABLES FROM $db_name";
$result = mysql_query($sql);

if (!$result) {
    echo "DB Error, could not list tables\n";
    echo 'MySQL Error: ' . mysql_error();
    exit;
}

echo "<table>";
  while ($row= mysql_fetch_row($result))
{

       echo "<tr>";
          echo "<td>{$row[0]}</td>"; 
echo "</tr>";
}
echo "</table>";
mysql_free_result($result);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.