从mySQL获取到HTML TABLE

I have used this code but its not fetching anything other than displaying the table on the web.

<!doctype html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>database connections</title>
    </head>
    <body>
      <?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("ticad", $connector)
        or die("Unable to connect");

      //execute the SQL query and return records
      $result = mysql_query("SELECT * FROM users ");

      ?>
      <table border="2" style= "background-color: #84ed86; color: #761a9b; margin: 0 auto;" >
      <thead>
        <tr>
          <th>id</th>
          <th>Names</th>
          <th>Company</th>
          <th>Position</th>
          <th>Email</th>
          <th>Event</th>
          <th>Comments</th>
        </tr>
      </thead>
      <tbody>
        <?php
          while( $row = mysql_fetch_assoc( $result ) ){
            echo
            "<tr>
              <td>{$row\['id'\]}</td>
              <td>{$row\['Names'\]}</td>
              <td>{$row\['Company'\]}</td>
              <td>{$row\['Position'\]}</td>
              <td>{$row\['Email'\]}</td>
              <td>{$row\['Event'\]}</td> 
              <td>{$row\['Comments'\]}</td> 
            </tr>
";
          }
        ?>
      </tbody>
    </table>
     <?php mysql_close($connector); ?>
    </body>
    </html>

This is my Table and dabase

This is what am getting when I run the code as a web. I want all the records to be displayed on the table as we fetch from the table users

dongluyi5123
dongluyi5123 您是在本地服务器(如XAMPP)上运行它还是像普通HTML文件一样打开它?同时删除'\'字符
大约 4 年之前 回复
doujinyi1267
doujinyi1267 PHP通常不在.html文件中执行,并且当您甚至不通过本地Web服务器上的HTTP查看文件时肯定不会执行,但是使用文件协议。所以你应该做的第一件事是阅读如何设置本地开发环境来测试PHP页面。
大约 4 年之前 回复

2个回答

try this and don't escape... And as I saw your picture. You need to upload your file onto webserver with support of PHP. Rename your file to .php extension

  echo
        "<tr>
          <td>".$row['id']."</td>
          <td>".$row['Names']."</td>
          <td>".$row['Company']."</td>
          <td>".$row['Position']."</td>
          <td>".$row['Email']."</td>
          <td>".$row['Event']."</td> 
          <td>".$row['Comments']."</td> 
        </tr>
";

Don't escape the brackets:

<td>{$row['id']}</td>
dsfs587465
dsfs587465 哦,问题是你需要在网络服务器上运行它。 不要只是将其作为HTML文件打开。
大约 4 年之前 回复
duanjun7801
duanjun7801 我改变了..但仍然是一样的。 <td> {$ row ['id']} </ td> <td> {$ row ['Names']} </ td> <td> {$ row ['Company']} </ td> <td > {$ row ['Position']} </ td> <td> {$ row ['Email']} </ td> <td> {$ row ['Comments']} </ td>
大约 4 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐