douxie3625 2016-10-01 09:14
浏览 302

将PHP代码转换为HTML

I have been having hard time trying to convert my php code to html for 5 hours and at this point, I'm really burned out :X. Here's my Php code

 <?php
  $con=mysqli_connect("localhost","dbuser","pw","dbname");
 // Check connection
 if (mysqli_connect_errno())
   {
   echo "Failed to connect to MySQL: " . mysqli_connect_error();
   }

 $result = mysqli_query($con,"SELECT * FROM tablea");

 echo "<table border='1'  >
 <tr>
 <th>id</th>
 <th>Subject_Code</th>
 <th>date</th>
 <th>name</th>
 <th>description</th>
 <th>Other_Details</th>
 </tr>";

 while($row = mysqli_fetch_array($result))
   {
   echo "<tr>";
   echo "<td>" . $row['id'] . "</td>";
   echo "<td>" . $row['Subject_Code'] . "</td>";
   echo "<td>" . $row['date'] . "</td>";
   echo "<td>" . $row['name'] . "</td>";
   echo "<td width='600' class='table_width'>" . $row['description'] . "</td>";
   echo "<td width='600' class='table_width' align='center'>" . $row['Other_Details'] . "</td>";
   echo "</tr>";
   }
 echo "</table>";

 mysqli_close($con);
 ?> 

and here's what i have done so far for HTML

<!doctype html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>database connections</title>
    </head>
    <body>
      <?php
      $username = "dbuser";
      $password = "pw";
      $host = "localhost";
      $database= "dbname";

      $connector = mysql_connect($localhost,$dbuser,$pw,dbname)
          or die("Unable to connect");
        echo "Connections are made successfully::";
      $selected = mysql_select_db("test_db", $connector)
        or die("Unable to connect");

      //execute the SQL query and return records
      $result = mysql_query("SELECT * FROM tablea ");
      ?>
      <table border="2">
      <thead>
        <tr>
          <th>id</th>
          <th>Subject_Code</th>
          <th>date</th>
          <th>name</th>
          <th>description</th>
          <td>Other_Details</td>
        </tr>
      </thead>
      <tbody>

        <?php
    while ($row = mysql_fetch_array($result)) {
        ?>
        <tr>
            <td><?php echo $row['id']; ?></td> 
            <td><?php echo $row['Subject_Code']; ?></td> 
            <td><?php echo $row['date']; ?></td> 
            <td><?php echo $row['name']; ?></td>
            <td><?php echo $row['description']; ?></td>
            <td><?php echo $row['Other_Details']; ?></td>
        </tr>

     <?php mysql_close($connector); ?>
    </body>
    </html>

little Help here please, Thanks !!

EDIT: seems like some people are not understanding my question. My php is working fine so i want to convert the php code into html. Basically, i want my table from database to show up using HTML table.

  • 写回答

3条回答 默认 最新

  • duan0427 2016-10-01 09:24
    关注

    you not close while;

    so change code to :

        <!doctype html>
            <html lang="en">
            <head>
              <meta charset="UTF-8">
              <title>database connections</title>
            </head>
            <body>
              <?php
    
    /////////////////////////////////// change \\\
              $username = "dbuser";
              $password = "pw";
              $host = "localhost";
              $database= "dbname";
    
              $connector = mysql_connect($localhost,$username,$password)
                  or die("Unable to connect");
                echo "Connections are made successfully::";
              $selected = mysql_select_db($database, $connector)
                or die("Unable to connect");
    
        /////////////////////////////////// end change \\\
    
              //execute the SQL query and return records
              $result = mysql_query("SELECT * FROM tablea ");
              ?>
              <table border="2">
              <thead>
                <tr>
                  <th>id</th>
                  <th>Subject_Code</th>
                  <th>date</th>
                  <th>name</th>
                  <th>description</th>
                  <td>Other_Details</td>
                </tr>
              </thead>
              <tbody>
    
                <?php
            while ($row = mysql_fetch_array($result)) :
                ?>
                <tr>
                    <td><?php echo $row['id']; ?></td> 
                    <td><?php echo $row['Subject_Code']; ?></td> 
                    <td><?php echo $row['date']; ?></td> 
                    <td><?php echo $row['name']; ?></td>
                    <td><?php echo $row['description']; ?></td>
                    <td><?php echo $row['Other_Details']; ?></td>
                </tr>
             <?php endwhile;?>
             <?php mysql_close($connector); ?>
            </body>
            </html>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序