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条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题