-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpresCand.php
More file actions
194 lines (189 loc) · 4.72 KB
/
Copy pathpresCand.php
File metadata and controls
194 lines (189 loc) · 4.72 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<?php
$dbh;
try
{
/*** connect to SQLite database ***/
$dbh = new PDO("sqlite:db/contrib.db");
}
catch(PDOException $e)
{
echo $e->getMessage();
echo "<br><br>Database -- NOT -- loaded successfully .. ";
die( "<br><br>Query Closed !!! $error");
}
$search = htmlspecialchars($_GET["name"]);
#$query = "SELECT * from CandsCRP12 WHERE FirstLastP LIKE '%$search%'";
$query = "SELECT * from CandsCRP12 WHERE CurrCand = 'Y' AND DistIDRunFor = 'PRES'";
header('Content-type: text/plain; charset=us-ascii');
$i=0;
$line="";
echo "[";
$num1 = 0;
foreach ($dbh->query($query) as $row) {
if ($num1 > 0) {
echo ",";
}
$num1 += 1;
echo "{";
echo "\"candidateName\": \"".$row["FirstLastP"]."\",";
echo "\"CID \": \"".$row["CID"]."\",";
echo "\"Party\": \"".$row["Party"]."\",";
echo "\"ranFor\": \"".$row["DistIDRunFor"]."\",";
echo "\"currentPosition\": \"".$row["DistIDCurr"]."\",";
echo "\"type\": \"".$row["CRPICO"]."\",";
echo "\"noPacs\": \"".$row["noPacs"]."\",";
$query2 = "SELECT distinct(RealCode), FECCandID from PACs12 WHERE FECCandID = '".$row["FECCandID"]."'";
echo "\"PACs\":[";
$map = array(
"Agribusiness"=> 0,
"Candidate"=> 0,
"Communic/Electronics"=> 0,
"Construction"=> 0,
"Defense"=>0,
"Energy/Nat Resource"=> 0,
"Finance/Insur/RealEst"=> 0 ,
"Health"=> 0,
"Ideology/Single-Issue"=> 0,
"Joint Candidate Cmtes"=> 0,
"Labor"=> 0,
"Lawyers & Lobbyists"=> 0,
"Misc Business"=> 0,
"Non-contribution"=> 0,
"Other"=> 0,
"Party Cmte"=> 0,
"Transportation"=> 0,
"Unknown"=>0);
foreach ($dbh->query($query2) as $row2) {
$query3 = "SELECT sum(Amount) as Amount, RealCode from PACs12 where RealCode = '".$row2["RealCode"]."' AND FECCandID = '".$row2["FECCandID"]."'";
$name;
$amount;
foreach ($dbh->query($query3) as $row3) {
$amount = $row3["Amount"];
}
$query3 = "SELECT sectorlong from categories where catcode = '".$row2["RealCode"]."'";
foreach ($dbh->query($query3) as $row3) {
$name = $row3["sectorlong"];
}
$map[$name] += $amount;
//echo "\"".$name."\":".$map[$name].",";
}
$num = 0;
if ($map["Agribusiness"] > 0) {
if ($num > 0) {
echo ",";
}
$num += 1;
echo "{\""."Agribusiness"."\":".$map["Agribusiness"]."}";
}
if ($map["Candidate"] > 0) {
if ($num > 0) {
echo ",";
}
$num += 1;
echo "{\""."Candidate"."\":".$map["Candidate"]."}";
}
if ($map["Communic/Electronics"] > 0) {
if ($num > 0) {
echo ",";
}
$num += 1;
echo "{\""."Communic/Electronics"."\":".$map["Communic/Electronics"]."}";
}
if ($map["Construction"] > 0) {
if ($num > 0) {
echo ",";
}
$num += 1;
echo "{\""."Construction"."\":".$map["Construction"]."}";
}
if ($map["Defense"] > 0) {
if ($num > 0) {
echo ",";
}
$num += 1;
echo "{\""."Defense"."\":".$map["Defense"]."}";
}
if ($map["Energy/Nat Resource"] > 0) {
if ($num > 0) {
echo ",";
}
$num += 1;
echo "{\""."Energy/Nat Resource"."\":".$map["Energy/Nat Resource"]."}";
}
if ($map["Finance/Insur/RealEst"] > 0) {
if ($num > 0) {
echo ",";
}
$num += 1;
echo "{\""."Finance/Insur/RealEst"."\":".$map["Finance/Insur/RealEst"]."}";
}
if ($map["Health"] > 0) {
if ($num > 0) {
echo ",";
}
$num += 1;
echo "{\""."Health"."\":".$map["Health"]."}";
}
if ($map["Ideology/Single-Issue"] > 0) {
if ($num > 0) {
echo ",";
}
$num += 1;
echo "{\""."Ideology/Single-Issue"."\":".$map["Ideology/Single-Issue"]."}";
}
if (($map["Joint Candidate Cmtes"] + $map["Party Cmte"]) > 0) {
if ($num > 0) {
echo ",";
}
$num += 1;
echo "{\""."Committee"."\":".($map["Joint Candidate Cmtes"] + $map["Party Cmte"])."}";
}
if (($map["Other"] + $map["Unknown"]) > 0) {
if ($num > 0) {
echo ",";
}
$num += 1;
echo "{\""."Other"."\":".($map["Other"] + $map["Unknown"])."}";
}
if ($map["Labor"] > 0) {
if ($num > 0) {
echo ",";
}
$num += 1;
echo "{\""."Labor"."\":".$map["Labor"]."}";
}
if ($map["Lawyers & Lobbyists"] > 0) {
if ($num > 0) {
echo ",";
}
$num += 1;
echo "{\""."Lawyers & Lobbyists"."\":".$map["Lawyers & Lobbyists"]."}";
}
if ($map["Misc Business"] > 0) {
if ($num > 0) {
echo ",";
}
$num += 1;
echo "{\""."Misc Business"."\":".$map["Misc Business"]."}";
}
if ($map["Non-contribution"] > 0) {
if ($num > 0) {
echo ",";
}
$num += 1;
echo "{\""."Non-contribution"."\":".$map["Non-contribution"]."}";
}
if ($map["Transportation"] > 0) {
if ($num > 0) {
echo ",";
}
$num += 1;
echo "{\""."Transportation"."\":".$map["Transportation"]."}";
}
echo "]";
$i=$i+1;
$line="";
echo "}";
}
echo "]";
?>