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 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配