将php代码转换为html [英] converting php code to html

查看:152
本文介绍了将php代码转换为html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

5个小时以来,我一直在尝试将我的php代码转换为html的过程很辛苦,在这一点上,我真的很疲倦:X. 这是我的PHP代码

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);
 ?> 

这是我到目前为止对HTML所做的事情

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 !!

似乎有些人不了解我的问题.我的php工作正常,因此我想将php代码转换为html.基本上,我希望数据库中的表使用HTML表显示.

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.

推荐答案

您不会关闭;

因此将代码更改为:

    <!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>

这篇关于将php代码转换为html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆