如何动态显示视图内容

时间:2016-04-19 13:05:42

标签: php mysql

我在MySQL中处理视图时使用PHP。我想动态显示此视图的HTML内容(列和数据)。所以我想根据视图显示数据。它必须找出视图和数据中的列数。如何使用PHP在HTML中显示它?

1 个答案:

答案 0 :(得分:0)

只是为了给你一个想法,但无论如何,我建议你去寻找一个教程并学习PHP。

 <html>
    <head></head>
    <body>
    <?php
    try{
          $con=new PDO("mysql::host=localhost;dbname=databasename;","username","password");
          $query="SELECT * FROM tablename ";
          $res=$con->query($query);
          $rows=$res->fetchAll(PDO::FETCH_BOTH);
          foreach($rows as $row)
          {
             echo $row["0"]."--".$row["1"]."--".$row["2"]."--".$row["3"]."--".$row["5"].<br>;//depends on how many columns you get in the query result
          }      
    }
    catch(PDOException $e){
        die("error:".$e->getMessage() );
    }
    ?>
    </body>
    </html>
相关问题