在html页面显示来自mysql / phpmyadmin的数据 [英] Display data from mysql/phpmyadmin on html page

查看:119
本文介绍了在html页面显示来自mysql / phpmyadmin的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 PHP 的初学者。
我试图把PHP放在HTML文件中,以便从我的数据库调用名为test的数据和名为myemployee的表。

我尝试了来自其他论坛的所有建议,但是我仍然没有得到显示在表格中,而是显示代码。

按照我的代码。我的代码中是否有错误?

I'm a beginner in PHP. I have tried to put PHP in HTML file in order to call data from my database called test and the table called myemployee.
I tried all the recommendation from other forum but I still did not get the display in table, instead, the code was displayed.
Following my code. Is there something wrong in my code?

即使我放入PHP文件,然后从HTML文件中调用,例如<?php include ('test.php')?> 它仍然无效。

Even if I put in PHP file and then, call from HTML file like this <?php include ('test.php')?> it still didn't work.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Home</title>
<link href="style/index-layout.css" rel="stylesheet" type="text/css" />
<link href="style/homepage-layout.css" rel="stylesheet" type="text/css"/>
</head>

<body>

<!--right-->
<div id="body">
<div id="left">

<br /><br />
<P ><B><h3>Progress</h3></FONT></B></P>

</div></div>
<?php
      $username = "root";
      $password = "";
      $host = "localhost";

      $connector = mysql_connect($host,$username,$password)
          or die("Unable to connect");
        echo "Connections are made successfully::";
      $selected = mysql_select_db("test", $connector)
        or die("Unable to connect");

      //execute the SQL query and return records
      $result = mysql_query("SELECT * FROM myemployee");
      ?>
<table>
      <thead>
        <tr>
          <th>Employee_id</th>
          <th>Employee_Name</th>
          <th>Employee_dob</th>
          <th>Employee_Adress</th>
          <th>Employee_dept</th>
          <th>Employee_salary</th>
        </tr>
      </thead>
      <tbody>
        <?php
          while( $row = mysql_fetch_assoc( $result ) ){
            echo "$row";
            echo
            "<tr>
              <td>{$row['employee_id']}</td>
              <td>{$row['employee_name']}</td>
              <td>{$row['employee_dob']}</td>
              <td>{$row['employee_addr']}</td>
              <td>{$row['employee_dept']}</td>
              <td>{$row['employee_sal']}</td> 
            </tr>";
          }
        ?>
      </tbody>
    </table>
     <?php mysql_close($connector); ?>
<br/><br/>

</body>
</html>


推荐答案

无需将其称为html文件。您可以将整个代码放在.php文件中并运行php文件。
我只是checke3d你的代码,我把它放在一个php文件中,并做了一些修改。它运作完美(显然没有风格)。
这里是代码:

No need to call it to an html file. You can put the entire code in a .php file and run the php file. i just checke3d your code and i put it in a php file and made some changes. It worked perfectly(without the styles obviously). here is the code:

<?php
 $username = "root";
 $password = "";
 $host = "localhost";
 $connector = mysql_connect($host, $username, $password)
    or die("Unable to connect");
 $selected = mysql_select_db("sample", $connector)
    or die("Unable to connect");
 ?>
 <!DOCTYPE html>
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
    <title>Home</title>
    <link href="style/index-layout.css" rel="stylesheet" type="text/css" />
    <link href="style/homepage-layout.css" rel="stylesheet" type="text/css"/>
 </head>
 <body>
    <!--right-->
    <div id="body">
        <div id="left">
        </div></div>
    <?php
    //execute the SQL query and return records
    $result = mysql_query("SELECT * FROM alte_brand");
    ?>
    <table>
        <thead>
            <tr>
                <th>Employee_id</th>
                <th>Employee_Name</th>

            </tr>
        </thead>
        <tbody>
            <?php
            while ($row = mysql_fetch_assoc($result)) {
                echo
                "<tr>
          <td>{$row['bid']}</td>
          <td>{$row['bname']}</td>
        </tr>";
            }
            ?>
        </tbody>
    </table>
 </body>
 </html>
<?php mysql_close($connector); ?>

这篇关于在html页面显示来自mysql / phpmyadmin的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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