Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <body>
- <h1>Database Select:</h1>
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "123456789";
- $dbname = "mydatabase";
- $conn = new mysqli($servername, $username, $password, $dbname);
- if($conn->connect_error){
- die("Connection failed: " .$conn->connect_error);
- }
- $sql = "SELECT * FROM student";
- $result = $conn->query($sql);
- $count = 0;
- if($result->num_rows > 0){
- print("<table>");
- while($row = $result->fetch_assoc()){
- if ($count == 0){
- print("<tr>");
- foreach ($row as $key => $value){
- print ("<th>$key</th>");
- }
- print ("</tr>");
- $count++;
- }
- print ("<tr>");
- foreach ($row as $key => $value){
- print ("<td>$value</td>");
- }
- print ("</tr>");
- }
- print ("</table>");
- }else{
- print ("0 results");
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement