Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. <?php
  2. // Connecting to the database
  3. $top = "<html>
  4. <head>
  5. <link rel="stylesheet" href="StyleSheet.css" type="text/css">
  6. <style>
  7. img {
  8. display: block;
  9. margin: 0 auto;
  10. }
  11. </style>
  12. <title>Shir & Chen's Garage</title>
  13. </head>
  14. <body style="text-align:center; font-family:verdana;">
  15. <h1>The Cars Data Base</h1>
  16. <img src="cars_disney.jpg" alt="Car"
  17. style="width:304px;height:228px;">
  18. <h5 style="text-align:center;">Our site will provide you all details about the cars we supply.</h5>
  19. <a href="add_new_car.php" target="_blank">Click here to add cars to the data base</a>
  20. <br><a href="add_new_part.php" target="_blank">Click here to add parts to the data base</a></br>
  21. <h2>Cars in Data Base</h2>";
  22.  
  23. $server = "tcp:shirfisher.database.windows.net,1433";
  24. $user = "shirfisher";
  25. $pass = "Q1W2r4e3";
  26. $database = "shirfisher";
  27. $c = array("Database" => $database, "UID" => $user, "PWD" => $pass);
  28. sqlsrv_configure('WarningsReturnAsErrors', 0);
  29. $conn = sqlsrv_connect($server, $c);
  30. if($conn === false)
  31. {
  32. echo "error";
  33. die(print_r(sqlsrv_errors(), true));
  34. }
  35.  
  36. $sql = "SELECT cars.Car_id, cars.Model, cars.Year_car, count(car_parts.Part_id) as Num
  37. FROM cars NATURAL JOIN relations_data NATURAL JOIN car_parts
  38. GROUP BY cars.Car_id, cars.Model, cars.Year_car;";
  39. $result = sqlsrv_query($conn, $sql);
  40. echo $top;
  41. 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>";
  42. while($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC))
  43. {
  44. echo "<tr><td>".$row["cars.Car_id"]."</td><td>'".$row["cars.Model"]."'</td><td>".$row["cars.Year_car"]."</td><td>'".$row["Num"]."'</td></tr>";
  45. }
  46. echo "</table>";
  47. echo "</body></html>";
  48. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement