Last active
June 19, 2018 08:19
-
-
Save danielkwok21/2533d28ccaa37d3c9628205b4d327790 to your computer and use it in GitHub Desktop.
Connected website + data from database
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<?php | |
include 'index.php'; //connects website to database | |
?> | |
<link href="potato.css" rel="stylesheet" type="text/css" /> | |
<html> | |
<head> | |
<h1>Hello potato</h1> | |
<p>It's a wonderful day</p> | |
<div>Square</div> | |
</head> | |
<body> | |
<?php | |
$sql = "SELECT Dish, Origin FROM dish_origins"; | |
$result = mysqli_query($conn, $sql); //apply query $sql to our database with credentials specified in $conn | |
if(mysqli_num_rows($result)>0){//if rows in result set > 0 | |
while($row = mysqli_fetch_assoc($result)){ //returns a result row in an array | |
echo "<h1>Dish:".$row["Dish"]."</h1>"."<p>Origin:".$row["Origin"]."<p>"; //displays data in database in html | |
} | |
}else{ | |
echo "0 results"; | |
} | |
?> | |
</body> | |
</html> | |
<?php | |
closecon($conn); //closes connection | |
echo "Connection closed"; | |
?> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> | |
<script type="text/javascript" src="potato.js"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment