SHARE
TWEET

lab6a1

Leslie_Wen Nov 8th, 2019 (edited) 163 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE HTML>
  2. <html lang="en">
  3. <head>
  4. <title>Lab 6 Activity A</title>
  5.  
  6. <link href="https://fonts.googleapis.com/css?family=Acme&display=swap" rel="stylesheet">
  7. <link href="https://fonts.googleapis.com/css?family=Acme|Hind+Siliguri&display=swap" rel="stylesheet">
  8. <style>
  9. body{text-align:center;font-size:20px;font-family:'Hind Siliguri',sans-serif;}
  10. img{max-width:700px;}
  11. h1,h2{font-family:'Acme',sans-serif;}
  12. </style>
  13. </head>
  14. <body>
  15. <?php
  16.  
  17. echo "<h1>Leslie Wen CPS530 Lab 6 Part I (PHP/MySql)</h1>";
  18. $conn=new mysqli("localhost", "l2wen", "JavnabMi", "l2wen");
  19.  
  20.  
  21. $sql="CREATE TABLE MyPhotos(
  22. id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  23. subject VARCHAR(30) NOT NULL,
  24. location VARCHAR(30) NOT NULL,
  25. date_taken VARCHAR(10) NOT NULL,
  26. url VARCHAR(300) NOT NULL
  27. )";
  28. #test if table is created
  29. if (mysqli_query($conn,$sql)){
  30.         echo "Table MyPhotos created successfully";
  31. }else{
  32.         echo "Error creating table: " . mysqli_error($conn);
  33. }
  34. echo "<br><br>";
  35. $sql="INSERT INTO MyPhotos(subject, location, date_taken, url)
  36. VALUES('CN Tower','Ontario','2018-04-01','https://q-cf.bstatic.com/images/hotel/max1024x768/124/124430241.jpg')";
  37. if ($conn->query($sql) === TRUE) {
  38.     $last_id = $conn->insert_id;
  39.     echo "Entry created successfully. Last inserted ID is: " . $last_id."<br>";
  40. } else {
  41.     echo "Error: " . $sql . "<br>" . $conn->error;
  42. }
  43. $sql="INSERT INTO MyPhotos(subject,location,date_taken,url)
  44. VALUES('Kingston City Hall','Ontario','2010-07-14','https://www.tvo.org/sites/default/files/styles/full_width_1280/public/article-thumbnails/Kingston_0.JPG?itok=9i2FcCOf')";
  45. if ($conn->query($sql) === TRUE) {
  46.     $last_id = $conn->insert_id;
  47.     echo "Entry created successfully. Last inserted ID is: " . $last_id."<br>";
  48. } else {
  49.     echo "Error: " . $sql . "<br>" . $conn->error;
  50. }
  51. $sql="INSERT INTO MyPhotos(subject,location,date_taken,url)
  52. VALUES('Burlington Shoreline','Ontario','2019-08-09','https://www.macleans.ca/wp-content/uploads/2019/08/BURLINGTON-COMMUNITIES-CANADA-810x608-1564678122.jpg')";
  53. if ($conn->query($sql) === TRUE) {
  54.     $last_id = $conn->insert_id;
  55.     echo "Entry created successfully. Last inserted ID is: " . $last_id."<br>";
  56. } else {
  57.     echo "Error: " . $sql . "<br>" . $conn->error;
  58. }
  59. #display by sorted date
  60. echo "<h2>Images sorted by date taken</h2><br>";
  61. $sql= "SELECT id,subject,location,date_taken FROM MyPhotos ORDER BY date_taken";
  62. $result = mysqli_query($conn,$sql);
  63. if(mysqli_num_rows($result)>0){
  64.         while($row=mysqli_fetch_assoc($result)){
  65.                 echo "Id: ".$row["id"]." -Subject: ".$row["subject"]." -Location: ".$row["location"]." -Date Taken: ".$row["date_taken"]. "<br>";
  66.         }
  67. }
  68. echo "<br><br>";
  69.  
  70.  
  71. #display images with location of Ontario
  72. echo "<h2>Images taken in Ontario</h2><br>";
  73. $sql = "SELECT subject, location, url FROM MyPhotos WHERE location = 'Ontario'";
  74.  
  75. $result = mysqli_query($conn, $sql);
  76.  
  77. if (mysqli_num_rows($result) > 0) {
  78.     while($row = mysqli_fetch_assoc($result)) {
  79.         echo  "<img src=" . $row["url"]."><br>Subject: " . $row["subject"]. " - Location: " . $row["location"]. "<br><br>";
  80.     }
  81. }
  82. $sql="DROP TABLE MyPhotos;";
  83. if (mysqli_query($conn, $sql)) {
  84.     echo "Table deleted successfully";
  85. } else {
  86.     echo "Error deleting the Table: " . mysqli_error($conn);
  87. }
  88. $conn->close();
  89. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top