dqd82461 2016-03-09 02:17 采纳率: 0%
浏览 41
已采纳

从数据库获取表名并将其输出到html表以供下载

I am attempting to get data from a mysql database. This is the code that I have so far:

include 'sqlConnection.php';
$strSQL = "SELECT * FROM PrimeSelectScan";
$rs = $sqlTableConnection->query($strSQL);
if ($sqlTableConnection->query($rs) === TRUE) {
    echo "Record updated successfully";
} else {
    echo "Error updating record: " . $sqlTableConnection->error;
} 
while($row = mysqli_fetch_array($rs)) 
{
    echo "\t<tr><td>".$row['id']."</td><td>".$row['cost']."</td><td>".$row['roi']."</td></tr>
";
}
$sqlTableConnection->close();

The sqlConnection.php file is just the connection to the database. I am not exactly sure if I am correct or not. If someone could help me out and lead me in the right direction, I would really appreciate it. This is the first time I have attempted to get information like this. Thanks in advance.

  • 写回答

2条回答 默认 最新

  • doucanshou6998 2016-03-09 02:42
    关注

    Are you getting any error messages?

    Here is an example for a mysqli query:

    $mysqli = new mysqli("localhost", "user", "pass", "db");
    $query  = "SHOW TABLES FROM primeselectscan";
    $result = $mysqli->query($query);
    
    header("Content-type: application/octet-stream");
    header("Content-Disposition: attachment; filename=FILE-NAME-HERE.txt");
    header("Pragma: no-cache");
    header("Expires: 0");
    
    while($row = $result->fetch_array()) {
        echo "\t<tr><td>".$row['Tables_in_primeselectscan']."</td><td>
    ";
    }
    
    $mysqli->close();
    

    If you are wanting the actual table names within the database then you need to change your query to use 'SHOW TABLES FROM dbName'. See http://dev.mysql.com/doc/refman/5.7/en/show-tables.html for details.

    To have it output as an actual download add the following headers before you output anything, I added that to the code section above.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?