/Users/johnr/Desktop/IA pdf Downloads/_New Projects Downloads May 7th/CS_IA_Mattew/GetMySQLData.class.php |
1 <?php
2 require_once 'MySQLConn.class.php';
3 class GetMySQLData extends MySQLConn {
4 public function getHotelData($destination, $rating){
5
6 https://phpdelusions.net/mysqli_examples/prepared_select
7 $conn = $this->connect();
8 if($rating == "any"){
9 $sql = "SELECT HotelName FROM hotel_data_2022 WHERE City=? ORDER BY HotelName ASC;";
10 $stmt = $conn->prepare($sql);
11 $stmt->bind_param("s", $destination);
12 }else{
13 $sql = "SELECT HotelName FROM hotel_data_2022 WHERE City=? AND Stars=? ORDER BY HotelName ASC;";
14 $stmt = $conn->prepare($sql);
15 $stmt->bind_param("ss", $destination, $rating);
16 }
17 $stmt->execute();
18 $result = $stmt->get_result();
19
20 $data = $result->fetch_all(MYSQLI_ASSOC);
21 $numRows = $result->num_rows;
22 if ($numRows > 0){
23
24 return $data;
25 }else{
26 return "No results";
27 }
28 }
29 public function getGolfCourseData($destination){
30
31 https://phpdelusions.net/mysqli_examples/prepared_select
32 $conn = $this->connect();
33 $sql = "SELECT GolfCourseName FROM golf_course_data_2022 WHERE City=? ORDER BY GolfCourseName ASC";
34 $stmt = $conn->prepare($sql);
35 $stmt->bind_param("s", $destination);
36 $stmt->execute();
37 $result = $stmt->get_result();
38
39 $data = $result->fetch_all(MYSQLI_ASSOC);
40 $numRows = $result->num_rows;
41 if ($numRows > 0){
42
43 return $data;
44 }else{
45 return "No results";
46 }
47 }
48 public function getTableData($table){
49 $conn = $this->connect();
50 $query = $conn->query("SELECT * FROM ".$table);
51 return $query;
52 }
53
54 public function getTableDataFromInquiryID($table, $inquiryID){
55 $conn = $this->connect();
56 $sql = "SELECT * FROM ".$table." WHERE InquiryID = ?";
57 $stmt = $conn->prepare($sql);
58 $stmt->bind_param("s", $inquiryID);
59 $stmt->execute();
60 $result = $stmt->get_result();
61 return $result;
62 }
63 public function getColumns($table){
64 $conn = $this->connect();
65 $sqlColumns = "SHOW COLUMNS FROM ".$table;
66 $columnsQuery = $conn->query($sqlColumns);
67 return $columnsQuery;
68 }
69 }
70