Jump to content

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);
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.