从Mysql动态检索数据到php页面

时间:2016-03-26 10:00:07

标签: javascript php jquery mysql

我需要动态地将mysql数据库中的数据显示为下面的html格式。由于我是php的新手,我想知道如何使用php做到这一点。数据应该在html代码中的模板中。

HTML code:

strcmp("", "")

PHP代码:

<div class = 'square-box' style = "width:977px; height:125px;">
  <div class = 'square-content' style = "padding:5px; background-color: #FAFAFA;"><div>
    <span style = "font-size: 10px;">
      <table>
        <tr>

          <td><label style = "font-size: 14px;">Company Name: &nbsp;
            </label></td>
          <td><input class = "form-control" style = "background:#FAFAFA; border-style:none; box-shadow: inset 0px 0px 0px 0px;" type = "text" name = "company_name"</td>

          <td><label style = "font-size: 14px;">&nbsp;Date of Audit: &nbsp;
            </label></td>
          <td><input class = "form-control" style = "background:#FAFAFA; border-style:none; box-shadow: inset 0px 0px 0px 0px;" type = "date" name = "audit_date"></td>
        <tr>

        <tr>
          <td><label style = "font-size: 14px;">Time: &nbsp;
            </label></td>
          <td><input class = "form-control" style = "background:#FAFAFA; border-style:none; box-shadow: inset 0px 0px 0px 0px;" type = "text" name = "audit_time"></td>

          <td><label style = "font-size: 14px;">&nbsp;
            Status: &nbsp;
            </label></td>
          <td><input class = "form-control" style = "background:#FAFAFA; border-style:none; box-shadow: inset 0px 0px 0px 0px;" type = "text" name = "audit_status"></td>
        <tr>

      </table>
      <table>
        <tr>
          <td><a href = "#" style = "font-size: 14px;">View Risks</a> <br>
            <a href = "#" style = "font-size: 14px;">View Report</a></td>
        </tr>
      </table>
    </span>

    </div>
 </div>

1 个答案:

答案 0 :(得分:0)

所以你需要一个while循环,你会做这样的事情:

<table>
<?php 
    while($r = mysql_fetch_array($retval)): ?> // end php and show html
<tr>
    <td><label style = "font-size: 14px;">Company Name: &nbsp;</label></td>
    <td><input class = "form-control" style = "background:#FAFAFA; border-style:none; box-shadow: inset 0px 0px 0px 0px;" type = "text" name = "company_name"</td>
</tr>
 //add other rows
    <?php endwhile;?>
</table>

然后只需回显$r['columnname']来定位你想要的内容,例如:

<td><label style = "font-size: 14px;"><?php echo $r['columnname']; ?></label></td>