Create links with one name of a mysql table and display its contents on another page. It's possible?

0

I'm trying to create a page in php that will fetch the name of several tables from a database, show the names of the tables, and create a link for each table. As soon as the user clicks the link, it is taken to another page where the contents of that table in which he clicked is shown. The problem is that I am not seeing a way to show the names of the tables and create the links automatically.
Can someone help?

    
asked by anonymous 13.07.2014 / 19:37

2 answers

5

There are a few ways to get the name of the tables, such as

SHOW TABLES;

or

SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'NOME_DO_SCHEMA';

With this you can mount a link as /conteudoTabela.php?tabela=NOME_DA_TABELA .

    
13.07.2014 / 20:38
0

Try:

<?php
$dbname = 'mysql_dbname';

if (!mysql_connect('mysql_host', 'mysql_user', 'mysql_password')) {
    echo 'Could not connect to mysql';
    exit;
}

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

while ($row = mysql_fetch_row($result)) {
    echo "Tabela: <a href='show_data.php?table=".$row[0]."'<br />";
}

?>

show_data.php

<?php
$db = 'nome_database';

$c = mysql_connect('host', 'user', 'pass');
$b = mysql_select_db($db, $c);

$tabela = $_GET['table'];

$sql = mysql_query("SELECT * FROM ".$tabela."");

while($data = mysql_fetch_array($sql)){

echo $data['campo1'];
}
?>
    
13.07.2014 / 21:59