创建具有表名称的链接,以便在单击时显示表信息

时间:2014-07-13 17:10:34

标签: php html mysql

我正在尝试创建一个显示多个mysql表名称的页面,并为每个表创建一个链接。当用户单击链接时,他将转到显示表内容的页面。

例如:

与表名链接。

<a href="contents.php">Table name</a>

用户单击该链接并转到页面contents.php。该页面打印表格内容。

例如,如果我有一个带有Name和Age列的表,并且在列中插入了John和24,那么页面将打印John和24.

如果有人可以帮助我,我感激不尽。

2 个答案:

答案 0 :(得分:1)

使用GET请求而不是发布请求会更容易。

<a href="contents.php?tableName=actual_table_name">Table name</a>

然后在你的contents.php文件中:

<?php 
$tablename = $_GET["tableName"] 

/* all your queries that you want to do with tablename goes here */

?>

答案 1 :(得分:0)

尝试这个...

$result = mysql_query("show tables"); // run the query and assign the result to $result
while($table = mysql_fetch_array($result)) { // go through each row that was returned in $result
      echo "<a href=\"content.php?tableName=".$table[0]."\" >".$table[0] . "</a><BR>";      // print the table that was returned on that row.
}

... content.php

if(isset($_GET["tableName"]))
{
$select="select *from ".$_GET["tableName"];
$result=mysql_query($select);
while($row=mysql_fetch_array($result))
{
echo $row["name"];
echo $row["age"];
}
}
相关问题