Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // PHP pages are server side so it can't be examinated from the user on the browser
- <?php
- $host = "ip:port"; //port might not be needed depending on your server
- $user = "username"; //username to access the DB
- $password = "password"; //leave it blank if there's no password
- $db = "databaseName"; //name of the DB
- $conn = mysqli_connect($host, $user, $password, $db); //create connection
- if (!$conn) {
- die("Connection error: " . mysqli_connect_errno());
- } else {
- echo "Connection was succesfully!"; // or if you have the HTML code in the same page, you can delete the else statement
- }
- ?>
- <html> //open HTML
- <head>
- <link rel="stylesheet" type="text/css" href="indexstyle.css"> //link to CSS
- </head>
- <body>
- <div id="container"> //create a div so you can modify the look on CSS
- <table> //creating table and the column and rows for your data output
- <tr>
- <th>ID</th>
- <th>Name</th>
- <th>Surname</th>
- </tr>
- <?php //re open PHP to create the query and ge the result
- $sql = "SELECT ID, name, surname FROM tableName"; //insert your SQL query here
- $result = $conn->query($sql);
- if ($result->num_rows > 0) { // output data of each row
- while($row = $result->fetch_assoc()) {
- $str = "<tr><td>". $row['ID']. "</td><td>". $row['name']. "</td><td>". $row['surname']. "</td></tr>"; //The output is set to a VAR, you can also directly do an ECHO on it
- echo strtoupper($str); //this makes everything in capital letters
- }
- echo "</table>"; //closing table
- } else {
- echo "Nothing found!"; //Something else
- }
- mysqli_close($conn); //remember to close the connection
- ?>
- </body>
- </html> //close HTML
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement