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 python天天向上类似问题,但没有清零
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)