-
Notifications
You must be signed in to change notification settings - Fork 0
/
Q.php
94 lines (75 loc) · 3.3 KB
/
Q.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php header("Content-type: text/xml; charset=utf-8"); ?>
<?xml-stylesheet type="text/xsl" href="Q.xsl"?>
<!DOCTYPE CoffeePlaces SYSTEM "http://course-dm2517-ht18.csc.kth.se/~simfors/DM2517/project/CoffeePlaces.dtd">
<coffeelist>
<?php
include 'logindetails.php';
echo $username, $password, $databasename,;
// Connect using host, username, password and databasename
$link = mysqli_connect('xml.csc.kth.se', $username, $password, $databasename);
include_once('session.php');
// Check connection
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
// The SQL query
$query = " SELECT placeName, price, location, offer, coffeeCard FROM CoffeePlace;";
// Execute the query
if (($result = mysqli_query($link, $query)) === false) {
printf("Query failed: %s<br />\n%s", $query, mysqli_error($link));
exit();
}
$returnstring = '';
// Loop over the resulting lines
while ($line = $result->fetch_object()) {
// Store results from each row in variables
$placeName = $line->placeName;
$price = $line->price;
$location = $line->location;
$offer = $line->offer;
$card = $line->coffeeCard;
// Store the result we want by appending strings to the variable $returnstring
$returnstring .= "<CoffeePlace>";
$returnstring .= "<placeName>$placeName</placeName>";
$returnstring .= "<price>$price</price>";
$returnstring .= "<location>$location</location>";
$returnstring .= "<offer>$offer</offer>";
$returnstring .= "<coffeeCard card='$card'></coffeeCard>";
$returnstring .= "</CoffeePlace>";
}
// Free result and just in case encode result to utf8 before returning
mysqli_free_result($result);
print utf8_encode($returnstring);
// The Grade query
$query2 = " SELECT placeName, personName, coffeeGrade, priceGrade, atmosphereGrade, uniqueAvGrade FROM Grade;";
// Execute the query
if (($result2 = mysqli_query($link, $query2)) === false) {
printf("Query failed: %s<br />\n%s", $query2, mysqli_error($link));
exit();
}
$returnstring2 = '';
// Loop over the resulting lines
while ($line = $result2->fetch_object()) {
// Store results from each row in variables
$placeName = $line->placeName;
$personName = $line->personName; // ändra till username sen!
$coffeeGrade = $line->coffeeGrade;
$priceGrade = $line->priceGrade;
$atmosphereGrade = $line->atmosphereGrade;
$uniqueAvGrade = $line->uniqueAvGrade;
// Store the result we want by appending strings to the variable $returnstring
$returnstring2 .= "<Grade>";
$returnstring2 .= "<placeName>$placeName</placeName>";
$returnstring2 .= "<personName>$personName</personName>";
$returnstring2 .= "<coffeeGrade>$coffeeGrade</coffeeGrade>";
$returnstring2 .= "<priceGrade>$priceGrade</priceGrade>";
$returnstring2 .= "<atmosphereGrade>$atmosphereGrade</atmosphereGrade>";
$returnstring2 .= "<uniqueAvGrade>$uniqueAvGrade</uniqueAvGrade>";
$returnstring2 .= "</Grade>";
}
// Free result and just in case encode result to utf8 before returning
mysqli_free_result($result2);
print utf8_encode($returnstring2);
?>
</coffeelist>