Skip to content

Instantly share code, notes, and snippets.

@danielkwok21
Last active June 19, 2018 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielkwok21/2533d28ccaa37d3c9628205b4d327790 to your computer and use it in GitHub Desktop.
Save danielkwok21/2533d28ccaa37d3c9628205b4d327790 to your computer and use it in GitHub Desktop.
Connected website + data from database
<!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