display data from database into html table

后端 未结 2 1121
庸人自扰
庸人自扰 2021-01-17 06:01

I\'m trying to display data from database into a table in html. here is my code:

php code:

if($_SERVER[\'REQUEST_METHOD\'] ==\'POST\')
{   
 $type_u         


        
相关标签:
2条回答
  • 2021-01-17 06:31

    You must take echo "</table>"; out of the while loop.

    0 讨论(0)
  • 2021-01-17 06:38

    Here is the solution total html with php and database connections

       <!doctype html>
        <html lang="en">
        <head>
          <meta charset="UTF-8">
          <title>database connections</title>
        </head>
        <body>
          <?php
          $username = "database-username";
          $password = "database-password";
          $host = "localhost";
    
          $connector = mysql_connect($host,$username,$password)
              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 table_one ");
          ?>
          <table border="2" style= "background-color: #84ed86; color: #761a9b; margin: 0 auto;" >
          <thead>
            <tr>
              <th>Employee_id</th>
              <th>Employee_Name</th>
              <th>Employee_dob</th>
              <th>Employee_Adress</th>
              <th>Employee_dept</th>
              <td>Employee_salary</td>
            </tr>
          </thead>
          <tbody>
            <?php
              while( $row = mysql_fetch_assoc( $result ) ){
                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>\n";
              }
            ?>
          </tbody>
        </table>
         <?php mysql_close($connector); ?>
        </body>
        </html>
    

    Source: retrieve data from db and display it in table in php .. see this code whats wrong with it?

    0 讨论(0)
提交回复
热议问题