Created
December 22, 2016 21:23
-
-
Save solebox/e437b0e795451c3b6ff5ae8224ff4082 to your computer and use it in GitHub Desktop.
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
<?php | |
// Connecting to the database | |
$top = "<html> | |
<head> | |
<link rel="stylesheet" href="StyleSheet.css" type="text/css"> | |
<style> | |
img { | |
display: block; | |
margin: 0 auto; | |
} | |
</style> | |
<title>Shir & Chen's Garage</title> | |
</head> | |
<body style="text-align:center; font-family:verdana;"> | |
<h1>The Cars Data Base</h1> | |
<img src="cars_disney.jpg" alt="Car" | |
style="width:304px;height:228px;"> | |
<h5 style="text-align:center;">Our site will provide you all details about the cars we supply.</h5> | |
<a href="add_new_car.php" target="_blank">Click here to add cars to the data base</a> | |
<br><a href="add_new_part.php" target="_blank">Click here to add parts to the data base</a></br> | |
<h2>Cars in Data Base</h2>"; | |
$server = "tcp:shirfisher.database.windows.net,1433"; | |
$user = "shirfisher"; | |
$pass = "Q1W2r4e3"; | |
$database = "shirfisher"; | |
$c = array("Database" => $database, "UID" => $user, "PWD" => $pass); | |
sqlsrv_configure('WarningsReturnAsErrors', 0); | |
$conn = sqlsrv_connect($server, $c); | |
if($conn === false) | |
{ | |
echo "error"; | |
die(print_r(sqlsrv_errors(), true)); | |
} | |
$sql = "SELECT cars.Car_id, cars.Model, cars.Year_car, count(car_parts.Part_id) as Num | |
FROM cars NATURAL JOIN relations_data NATURAL JOIN car_parts | |
GROUP BY cars.Car_id, cars.Model, cars.Year_car;"; | |
$result = sqlsrv_query($conn, $sql); | |
echo $top; | |
echo "<table border = '1'><tr><th> Car ID </th><th> Car Model </th><th> Car Year </th><th> Number Of Parts in the car </th></tr>"; | |
while($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) | |
{ | |
echo "<tr><td>".$row["cars.Car_id"]."</td><td>'".$row["cars.Model"]."'</td><td>".$row["cars.Year_car"]."</td><td>'".$row["Num"]."'</td></tr>"; | |
} | |
echo "</table>"; | |
echo "</body></html>"; | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment