-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprojectSQL.php
executable file
·108 lines (90 loc) · 2.28 KB
/
projectSQL.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
include 'dbConnExec.php';
function mostRecentPublic()
{
$query = <<<STR
SELECT TOP 10 *
FROM Recipe r
Where r.IsPublic = 1
ORDER BY RecipeID
STR;
//WHERE public =
return executeQuery($query);
}
function getCategories()
{
$query = <<<STR
Select categoryid, categoryname
From category
Order by categoryid
STR;
return executeQuery($query);
}
function getAllergie()
{
$query = <<<STR
Select allergieID, allergiename
From allergies
Order by allergieID
STR;
return executeQuery($query);
}
function getTimeOfYear()
{
$query = <<<STR
Select timeofyear
From recipe
order by timeofyear
STR;
return executeQuery($query);
}
function searchForRecipe($userID, $recipename, $timeOfYear, $categoryID, $allergieID)
{
$cat = 'OR';
if (!isset($_SESSION['userinfo'])) {
$userID = 52;
}
if ($categoryID!=3) {
$cat = 'AND';
}
if ($allergieID!=1) {
$aller = 'AND';
} else {
$aller = "OR";
}
$query = <<<STR
Select *
From Recipe r INNER JOIN Allergies a
ON r.AllergieID=a.AllergieID
INNER JOIN Category c
ON r.CategoryID=c.CategoryID
Where (r.IsPublic=1 OR r.userID=$userID)
AND (recipename LIKE '%$recipename%')
AND r.timeOfYear LIKE '%$timeOfYear%'
$cat r.CategoryID=$categoryID
$aller r.AllergieID=$allergieID
STR;
return executeQuery($query);
}
function getACategory($categoryPK) {
$query = <<<STR
Select categoryname
From category
Where categoryid = $categoryPK
STR;
return executeQuery($query);
}
function getAAllergie($allergieID) {
$query = <<<STR
Select allergiename
From allergies
Where allergieid = $allergieID
STR;
return executeQuery($query);
}
?>