Skip to content

Instantly share code, notes, and snippets.

@quickgrid
Last active September 3, 2024 07:08
Show Gist options
  • Save quickgrid/35d3bcc75724aca3f889153c3ef7afff to your computer and use it in GitHub Desktop.
Save quickgrid/35d3bcc75724aca3f889153c3ef7afff to your computer and use it in GitHub Desktop.

Revisions

  1. quickgrid revised this gist Oct 19, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion mysql database to bootstrap table.php
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@

    <?php

    //
    //Change the password to match your configuration
    $link = mysqli_connect("localhost", "root", "yourPassword", "cse");

    // Check connection
  2. quickgrid revised this gist Oct 19, 2016. 1 changed file with 6 additions and 35 deletions.
    41 changes: 6 additions & 35 deletions mysql database to bootstrap table.php
    Original file line number Diff line number Diff line change
    @@ -10,8 +10,6 @@
    </head>
    <body>



    <?php

    //
    @@ -26,29 +24,21 @@

    $sql = "SELECT id, name, salary FROM instructor";
    $result = $link->query($sql);





    echo "<div class='container'>";
    echo "<div class='row-fluid'>";


    echo "<div class='col-xs-6'>";
    echo "<div class='table-responsive'>";


    echo "<table class='table table-hover table-inverse'>";


    echo "<tr>";
    echo "<th>ID</th>";
    echo "<th>Name</th>";
    echo "<th>Salary</th>";
    echo "</tr>";




    if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
    @@ -63,7 +53,6 @@
    echo "0 results";
    }


    echo "</table>";


    @@ -79,8 +68,6 @@
    echo "<th>year</th>";
    echo "</tr>";



    if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
    @@ -99,9 +86,6 @@
    echo "</div>";
    echo "</div>";




    /*
    * second table
    */
    @@ -119,9 +103,7 @@
    echo "<th>Department</th>";
    echo "<th>credits</th>";
    echo "</tr>";




    if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
    @@ -148,8 +130,7 @@
    /*
    * second row
    */



    $sql = "SELECT building, room_number, time_slot_id FROM section";
    $result = $link->query($sql);

    @@ -165,9 +146,7 @@
    echo "<th>room_number</th>";
    echo "<th>time_slot_id</th>";
    echo "</tr>";




    if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
    @@ -187,8 +166,6 @@
    echo "</div>";
    echo "</div>";




    /*
    * second table
    @@ -207,8 +184,6 @@
    echo "<th>Prerequite ID</th>";
    echo "</tr>";



    if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
    @@ -227,14 +202,10 @@
    echo "</div>";
    echo "</div>";


    echo "</div>";


    echo "</div>";




    // Close connection
    mysqli_close($link);
    ?>
  3. quickgrid created this gist Oct 19, 2016.
    244 changes: 244 additions & 0 deletions mysql database to bootstrap table.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,244 @@
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <title>Sample PHP Database Application</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.5/css/bootstrap.min.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.5/js/bootstrap.min.js"></script>
    </head>
    <body>



    <?php

    //
    $link = mysqli_connect("localhost", "root", "yourPassword", "cse");

    // Check connection
    if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
    }
    echo "<br>";


    $sql = "SELECT id, name, salary FROM instructor";
    $result = $link->query($sql);




    echo "<div class='container'>";
    echo "<div class='row-fluid'>";


    echo "<div class='col-xs-6'>";
    echo "<div class='table-responsive'>";


    echo "<table class='table table-hover table-inverse'>";


    echo "<tr>";
    echo "<th>ID</th>";
    echo "<th>Name</th>";
    echo "<th>Salary</th>";
    echo "</tr>";



    if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {

    echo "<tr>";
    echo "<td>" . $row["id"] . "</td>";
    echo "<td>" . $row["name"] . "</td>";
    echo "<td>" . $row["salary"] . "</td>";
    echo "</tr>";
    }
    } else {
    echo "0 results";
    }


    echo "</table>";


    $sql = "SELECT semester, year FROM section";
    $result = $link->query($sql);


    echo "<table class='table table-hover table-inverse'>";


    echo "<tr>";
    echo "<th>semester</th>";
    echo "<th>year</th>";
    echo "</tr>";



    if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {

    echo "<tr>";
    echo "<td>" . $row["semester"] . "</td>";
    echo "<td>" . $row["year"] . "</td>";
    echo "</tr>";
    }
    } else {
    echo "0 results";
    }

    echo "</table>";

    echo "</div>";
    echo "</div>";




    /*
    * second table
    */
    $sql = "SELECT course_id, title, dept_name, credits FROM course";
    $result = $link->query($sql);

    echo "<div class='col-xs-6'>";
    echo "<div class='table-responsive'>";

    echo "<table class='table table-hover table-inverse'>";

    echo "<tr>";
    echo "<th>Course ID</th>";
    echo "<th>Title</th>";
    echo "<th>Department</th>";
    echo "<th>credits</th>";
    echo "</tr>";



    if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {

    echo "<tr>";
    echo "<td>" . $row["course_id"] . "</td>";
    echo "<td>" . $row["title"] . "</td>";
    echo "<td>" . $row["dept_name"] . "</td>";
    echo "<td>" . $row["credits"] . "</td>";
    echo "</tr>";
    }
    } else {
    echo "0 results";
    }
    echo "</table>";

    echo "</div>";
    echo "</div>";


    echo "</div>";


    /*
    * second row
    */


    $sql = "SELECT building, room_number, time_slot_id FROM section";
    $result = $link->query($sql);

    echo "<div class='row-fluid'>";

    echo "<div class='col-xs-6'>";
    echo "<div class='table-responsive'>";

    echo "<table class='table table-hover table-inverse'>";

    echo "<tr>";
    echo "<th>building</th>";
    echo "<th>room_number</th>";
    echo "<th>time_slot_id</th>";
    echo "</tr>";



    if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {

    echo "<tr>";
    echo "<td>" . $row["building"] . "</td>";
    echo "<td>" . $row["room_number"] . "</td>";
    echo "<td>" . $row["time_slot_id"] . "</td>";
    echo "</tr>";
    }
    } else {
    echo "0 results";
    }

    echo "</table>";

    echo "</div>";
    echo "</div>";




    /*
    * second table
    */
    $sql = "SELECT course_id, prereq_id FROM prereq";
    $result = $link->query($sql);


    echo "<div class='col-xs-6'>";
    echo "<div class='table-responsive'>";

    echo "<table class='table table-hover table-inverse'>";

    echo "<tr>";
    echo "<th>Course ID</th>";
    echo "<th>Prerequite ID</th>";
    echo "</tr>";



    if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {

    echo "<tr>";
    echo "<td>" . $row["course_id"] . "</td>";
    echo "<td>" . $row["prereq_id"] . "</td>";
    echo "</tr>";
    }
    } else {
    echo "0 results";
    }

    echo "</table>";

    echo "</div>";
    echo "</div>";


    echo "</div>";


    echo "</div>";



    // Close connection
    mysqli_close($link);
    ?>


    </body>
    </html>