Rida
Rida

Reputation: 3

table class not working after inserting sql database inside

I firstly did the table layout and made sure everything is working, after connecting the table to a database and trying to put the records inside it, everything worked perfectly, but the class didnt, i have now the boring table without the layout made.

    <body>
     <h1>Employees</h1>
     <table class="responstable">
    <?php
    require 'connection.php';
    $conn    = Connect();



    $result = mysqli_query($conn,"SELECT * FROM employee");


    echo "<table border='1'>


      <tr>
        <th>Id</th>
        <th>First name</th>
        <th>Last name</th>
        <th>Salary</th>
        <th>Start Date</th>
        <th>Department</th>
      </tr>";


    while($row = mysqli_fetch_array($result))
    {
    echo "<tr>";
    echo "<td>" . $row['id'] . "</td>";
    echo "<td>" . $row['firstname'] . "</td>";
    echo "<td>" . $row['lastname'] . "</td>";
    echo "<td>" . $row['salary'] . "</td>";
    echo "<td>" . $row['startdate'] . "</td>";
    echo "<td>" . $row['department'] . "</td>";
    echo "</tr>";
    }
    echo "</table>";

    mysqli_close($conn);
    ?>



      <script src='http://cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.js'></script>


    </body>
    </html>

the table class is "responstable"

Upvotes: 0

Views: 41

Answers (1)

prabushitha
prabushitha

Reputation: 1483

table tag is defined in 2 places.try removing this.

echo "<table border='1'>

or remove the table tag at the top after h1 tag and add the class to the table tag defined in the echo as, complete code

<body>
     <h1>Employees</h1>
    <?php
    require 'connection.php';
    $conn    = Connect();



    $result = mysqli_query($conn,"SELECT * FROM employee");


    echo "<table border='1' class='responstable'>


      <tr>
        <th>Id</th>
        <th>First name</th>
        <th>Last name</th>
        <th>Salary</th>
        <th>Start Date</th>
        <th>Department</th>
      </tr>";


    while($row = mysqli_fetch_array($result))
    {
    echo "<tr>";
    echo "<td>" . $row['id'] . "</td>";
    echo "<td>" . $row['firstname'] . "</td>";
    echo "<td>" . $row['lastname'] . "</td>";
    echo "<td>" . $row['salary'] . "</td>";
    echo "<td>" . $row['startdate'] . "</td>";
    echo "<td>" . $row['department'] . "</td>";
    echo "</tr>";
    }
    echo "</table>";

    mysqli_close($conn);
    ?>



      <script src='http://cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.js'></script>


    </body>
    </html>

Upvotes: 2

Related Questions