-
Notifications
You must be signed in to change notification settings - Fork 1
/
jsout.php
89 lines (73 loc) · 2.38 KB
/
jsout.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
<?php
//sdelete from projects;delete from fields; delete from details;
/**
Json webservice that connects to projects database.
@usage:
call without parameters to get json out for all current projects
call with post/get params target = id to get specific target project
include in php with $store = true to get output in variable $store
**/
$SERVER = "localhost";
$USER = "spotco_sql";
$PASSWORD = "dododo";
$DBNAME = "spotco_ashaproject";
$DB = new PDO("mysql:dbname=$DBNAME;host=$SERVER", $USER, $PASSWORD);
$select_proj;
if (isset($_REQUEST["target"]) && is_numeric($_REQUEST["target"])) {
$tar = $_REQUEST["target"];
$select_proj = $DB->prepare("SELECT * from projects WHERE p_id = $tar");
} else {
$select_proj = $DB->prepare('SELECT * from projects');
}
$select_proj->execute();
$projects = $select_proj->fetchAll();
$projects_o = array();
foreach ($projects as $projects_array_index => $project) {
$project_name = $project["project_name"];
$focus = $project["focus"];
$img_url = $project["image_url"];
$img_style = $project["image_style"];
$date = $project["date"];
$video = $project["video"];
$p_id = $project["p_id"];
$project_o = array();
$project_o["project_name"] = $project_name;
$project_o["p_id"] = $p_id;
$project_o["focus"] = $focus;
$project_o["img_url"] = $img_url;
$project_o["img_style"] = $img_style;
$project_o["date"] = $date;
$project_o["video"] = $video;
$project_o_fields = array();
$p_id = $project["p_id"];
$select_fields = $DB->prepare("SELECT * FROM fields WHERE for_key_p_id = $p_id");
$select_fields->execute();
$fields = $select_fields->fetchAll();
foreach ($fields as $fields_array_index => $field) {
$field_name = $field["field_name"];
$f_id = $field["f_id"];
$field_o = array();
$field_o["name"] = $field_name;
$field_o_details = array();
$select_details = $DB->prepare("SELECT * FROM details WHERE for_key_f_id = $f_id");
$select_details->execute();
$details = $select_details->fetchAll();
foreach ($details as $detail_array_index => $detail) {
$detail_name = $detail["detail_name"];
array_push($field_o_details,$detail_name);
}
$field_o["details"] = $field_o_details;
array_push($project_o_fields,$field_o);
}
$project_o["fields"] = $project_o_fields;
array_push($projects_o, $project_o);
}
$js_o = array();
$js_o["array"] = $projects_o;
$jsout = json_encode($js_o);
if (!$store) {
echo $jsout;
} else {
$store = $jsout;
}
?>