-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
680 lines (506 loc) · 24.4 KB
/
functions.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
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
<?php
function getMainStorySQL() {
// this function retrieves the first article in the database, and is therefore
// presented as the 'main' article.
// connect to the database
$hostname='localhost';
$username='unn_w15002812';
$password='RYNUZTYA';
$dbh = new PDO("mysql:host=$hostname;dbname=unn_w15002812",$username,$password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try {
$mainStorySQL= "SELECT articleID, articleTitle, articleSub, articleCat, articleFlavourText, articleDate, articleAuth
FROM articles
ORDER BY articleDate DESC
LIMIT 1";
// sort by DESC to get the most recent first
// limit the query to only retrieve 1
$queryResult = $dbh->prepare($mainStorySQL);
$queryResult->execute();
if ($dbh->query($mainStorySQL)) {
while ($rowObj = $queryResult->fetchObject()) {
// set variables as rows from the table
$eTitle = $rowObj->articleTitle;
$eSubtitle = $rowObj->articleSub;
$eCategory = $rowObj->articleCat;
$eFlavourText = $rowObj->articleFlavourText;
$eDate = $rowObj->articleDate;
$eAuth = $rowObj->articleAuth;
// this echo outputs all of the above variables,
// segmented into their own divs/spans so as to be formatted individually
echo "<div class='mainArticle'>
<div id='main-article-left'>
<span class='articleCategory'>$eCategory</span>
<a href='article.php?articleID={$rowObj->articleID}'<span class='mainArticleTitle'>$eTitle</span></a>
<span class='mainArticleSubtitle'>$eSubtitle</span>
</div>
<div id='main-article-right'>
<span class='mainarticleFlavourText'>$eFlavourText</span>
<span class='mainArticleDate'>$eDate</span>
<span class='mainArticleAuthor'>$eAuth</span>
</div>
</div>";
}
}
// catch exception, echo out the exception message
} catch(PDOException $e) {
echo $e->getMessage();
}
}
function getTopThreeStoriesSQL() {
// this function retrieves 3 articles, but only after the first article
// therefore becoming the next top 3 articles, all sorted by their submission date
// connect to database
$hostname='localhost';
$username='unn_w15002812';
$password='RYNUZTYA';
$dbh = new PDO("mysql:host=$hostname;dbname=unn_w15002812",$username,$password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$topThreeSQL = "SELECT articleID, articleTitle, articleSub, articleCat, articleFlavourText, articleDate, articleAuth
FROM articles
ORDER BY articleDate DESC
LIMIT 1,4";
// using LIMIT to 3 articles AFTER the first article,
// essentially working as a desired 'range'
$queryResult = $dbh->prepare($topThreeSQL);
$queryResult->execute();
if ($dbh->query($topThreeSQL)) {
while ($rowObj = $queryResult->fetchObject()) {
$eTitle = $rowObj->articleTitle;
$eSubtitle = $rowObj->articleSub;
$eCategory = $rowObj->articleCat;
$eFlavourText = $rowObj->articleFlavourText;
$eDate = $rowObj->articleDate;
$eAuth = $rowObj->articleAuth;
// output is the same as the last function, however they are differently named
// so as to be differently styled from the previous articles
// each section has its own layout
echo "<div class='topThreeArticle'>
<span class='articleCategory'>$eCategory</span>
<a href='article.php?articleID={$rowObj->articleID}'<span class='topThreeArticleTitle'>$eTitle</span></a>
<span class='topThreeArticleSubtitle'>$eSubtitle</span>
<span class='topThreearticleFlavourText'>$eFlavourText</span>
<span class='topThreeArticleDate'>$eDate</span>
<span class='topThreeArticleAuthor'>$eAuth</span>
</div>";
}
}
$dbh = null;
}
function getMoreTopStoriesSQL() {
// this is the same as the last function, however now it is retrieving
// four articles opposed to three, AFTER the previous three articles
$hostname='localhost';
$username='unn_w15002812';
$password='RYNUZTYA';
$dbh = new PDO("mysql:host=$hostname;dbname=unn_w15002812",$username,$password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$moreTopSQL = "SELECT articleID, articleTitle, articleSub, articleCat, articleFlavourText, articleDate, articleAuth
FROM articles
ORDER BY articleDate DESC
LIMIT 4,4";
// using LIMIT as a range once again, this time getting four articles
$queryResult = $dbh->prepare($moreTopSQL);
$queryResult->execute();
if ($dbh->query($moreTopSQL)) {
while ($rowObj = $queryResult->fetchObject()) {
$eTitle = $rowObj->articleTitle;
$eSubtitle = $rowObj->articleSub;
$eCategory = $rowObj->articleCat;
$eFlavourText = $rowObj->articleFlavourText;
$eFlavourText = (strlen($eFlavourText) > 235) ? substr($eFlavourText,0,233).'..' : $eFlavourText; // cut off text that goes too long
$eDate = $rowObj->articleDate;
$eAuth = $rowObj->articleAuth;
// the only significant difference here is the introduction of an image tag
echo "<div class='moreTopArticle'>
<img src='http://via.placeholder.com/500x500' class='moreTopImg'>
<span class='articleCategory'>$eCategory</span>
<a href='article.php?articleID={$rowObj->articleID}'<span class='moreTopArticleTitle'>$eTitle</span></a>
<span class='moreToparticleFlavourText'>$eFlavourText</span>
<span class='moreTopArticleDate'>$eDate</span>
<span class='moreTopArticleAuthor'>$eAuth</span>
</div>";
}
}
$dbh = null;
}
function getSmallEntStoriesSQL() {
// this is for one of the two sections of the site designed to be 'mini' sections,
// that are small and unobtrusive, and providing enough visual difference as to be noticable
// among all of the text on the site
//connect to db
$hostname='localhost';
$username='unn_w15002812';
$password='RYNUZTYA';
$dbh = new PDO("mysql:host=$hostname;dbname=unn_w15002812",$username,$password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$moreTopSQL = "SELECT articleID, articleTitle, articleSub, articleCat, articleAuth
FROM articles
WHERE articleCat = 'entertainment'
ORDER BY articleDate DESC
LIMIT 1,3";
// only retrieve articles with their category matching entertainment
// limit to only 3 articles as that's how many divs will be displayed on the homepage
$queryResult = $dbh->prepare($moreTopSQL);
$queryResult->execute();
if ($dbh->query($moreTopSQL)) {
while ($rowObj = $queryResult->fetchObject()) {
$eTitle = $rowObj->articleTitle;
$eTitle = (strlen($eTitle) > 50) ? substr($eTitle,0,48).'..' : $eTitle; // cut off text that goes too long
$eSubtitle = $rowObj->articleSub;
$eAuth = $rowObj->articleAuth;
echo "<div class='smallEntArticle'>
<a href='article.php?articleID={$rowObj->articleID}'<span class='smallEntArticleTitle'>$eTitle</span></a>
<span class='smallEntArticleSubtitle'>$eSubtitle</span>
<span class='smallEntArticleAuthor'>$eAuth</span>
</div>";
}
}
$dbh = null;
}
function getSmallFashStoriesSQL() {
// the second mini section, this time for fashion articles
// connect to db
$hostname='localhost';
$username='unn_w15002812';
$password='RYNUZTYA';
$dbh = new PDO("mysql:host=$hostname;dbname=unn_w15002812",$username,$password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$moreTopSQL = "SELECT articleID, articleTitle, articleSub, articleCat, articleAuth
FROM articles
WHERE articleCat = 'fashion'
ORDER BY articleDate DESC
LIMIT 0,4";
// only get articles with their category being fashion
// limited to only 3 articles, despite the limit being syntactically different this time
// think it's because there's 3 articles total in 'fasion'
$queryResult = $dbh->prepare($moreTopSQL);
$queryResult->execute();
if ($dbh->query($moreTopSQL)) {
while ($rowObj = $queryResult->fetchObject()) {
$eTitle = $rowObj->articleTitle;
$eTitle = (strlen($eTitle) > 50) ? substr($eTitle,0,48).'..' : $eTitle; // cut off text that goes too long
$eSubtitle = $rowObj->articleSub;
$eAuth = $rowObj->articleAuth;
echo "<div class='smallFashArticle'>
<a href='article.php?articleID={$rowObj->articleID}'<span class='smallFashArticleTitle'>$eTitle</span></a>
<span class='smallFashArticleSubtitle'>$eSubtitle</span>
<span class='smallFashArticleAuthor'>$eAuth</span>
</div>";
}
}
$dbh = null;
}
function getVisualArticlesSQL() {
// this function retrieves the 'visual articles', that have additional fields and are in a seperate table
// so it's necessary for this to be its own function
// connect to db
$hostname='localhost';
$username='unn_w15002812';
$password='RYNUZTYA';
$dbh = new PDO("mysql:host=$hostname;dbname=unn_w15002812",$username,$password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$getVisualArticlesSQL = "SELECT articleID, articleTitle, articleFirstImg
FROM visual_articles
ORDER BY articleDate DESC";
// get data from visual_articles table this time, again sort by newest
// retrieves the first image in the article to be used as the thumbnail image
$queryResult = $dbh->prepare($getVisualArticlesSQL);
$queryResult->execute();
if ($dbh->query($getVisualArticlesSQL)) {
while ($rowObj = $queryResult->fetchObject()) {
$eTitle = $rowObj->articleTitle;
$eTitle = (strlen($eTitle) > 50) ? substr($eTitle,0,48).'..' : $eTitle; // cut off text that goes too long
$eImg = $rowObj->articleFirstImg;
echo "<div class='visualArticle'>
<a href='visualArticle.php?articleID={$rowObj->articleID}'><img src='$eImg' class='visualImg'></a>
<a href='visualArticle.php?articleID={$rowObj->articleID}'<span class='visualArticleTitle'>$eTitle</span></a>
</div>";
} // both the image and the article title are hyperlinks, as mobile users will likely click on the image itself
}
$dbh = null;
}
function retrieveArticleSQL() {
// function retrieves and outputs the full article info
// to be called on article.php
// gets the articleID, in order to retrieve ONLY the article matching a specific ID
$articleID = isset($_REQUEST['articleID']) ? ($_REQUEST['articleID']) : null;
// used to dynamically set the page title to match the article's title
$pageTitle = isset($_REQUEST['articleTitle']) ? ($_REQUEST['articleTitle']) : null;
$hostname='localhost';
$username='unn_w15002812';
$password='RYNUZTYA';
$dbh = new PDO("mysql:host=$hostname;dbname=unn_w15002812",$username,$password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sqlQuery = "SELECT *
FROM articles
WHERE articleID = $articleID";
// get everythinggggg
// where the articleID is the one the user requested (from clicking)
$queryResult = $dbh->prepare($sqlQuery);
$queryResult->execute();
while ($rowObj = $queryResult->fetch(PDO::FETCH_OBJ)) {
$eID = $rowObj->articleID;
$eTitle = $rowObj->articleTitle;
$eSubtitle = $rowObj->articleSub;
$eCat = $rowObj->articleCat;
$eDate = $rowObj->articleDate;
$eAuthor = $rowObj->articleAuth;
$eFlavourText = $rowObj->articleFlavourText;
$eFullText = $rowObj->articleFullText;
}
echo "<span class='articleCategory'>$eCat</span>
<span class='retArticleTitle'>$eTitle</span>
<span class='retArticleAuthor' style='margin-left:0;margin-right:1rem'>$eAuthor</span>
<span class='retArticleDate'>$eDate</span>
<span class='retarticleFlavourText'>$eFlavourText</span>
<span class='retarticleFullText'>$eFullText</span>
";
}
function retrieveVisualArticleSQL() {
// function is the same as the last function, but instead for the visual-articles
// as they have a different layout to accomodate all of the images
// and, again, as theyre in a seperate table
$articleID = isset($_REQUEST['articleID']) ? ($_REQUEST['articleID']) : null;
$pageTitle = isset($_REQUEST['articleTitle']) ? ($_REQUEST['articleTitle']) : null;
$hostname='localhost';
$username='unn_w15002812';
$password='RYNUZTYA';
$dbh = new PDO("mysql:host=$hostname;dbname=unn_w15002812",$username,$password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sqlQuery = "SELECT *
FROM visual_articles
WHERE articleID = $articleID";
$queryResult = $dbh->prepare($sqlQuery);
$queryResult->execute();
while ($rowObj = $queryResult->fetch(PDO::FETCH_OBJ)) {
$eID = $rowObj->articleID;
$eTitle = $rowObj->articleTitle;
$eCat = $rowObj->articleCat;
$eDate = $rowObj->articleDate;
$eAuthor = $rowObj->articleAuth;
$eFirstImg = $rowObj->articleFirstImg;
$eFirstText = $rowObj->articleFirstText;
$eSecondImg = $rowObj->articleSecondImg;
$eSecondText = $rowObj->articleSecondText;
$eThirdImg = $rowObj->articleThirdImg;
$eThirdText = $rowObj->articleThirdText;
// get all of the images and text fields
}
echo "<span class='articleCategory'>$eCat</span>
<span class='retArticleTitle'>$eTitle</span>
<span class='mainArticleAuthor' style='margin-left:0;margin-right:1rem'>$eAuthor</span>
<span class='mainArticleDate'>$eDate</span>
<img class='retVisualArticleImg' src='$eFirstImg' style='margin-top:6rem'/>
<p class='retVisualArticleText'>$eFirstText</p>
<img class='retVisualArticleImg' src='$eSecondImg'/>
<p class='retVisualArticleText'>$eSecondText</p>
<img class='retVisualArticleImg' src='$eThirdImg'/>
<p class='retVisualArticleText'>$eThirdText</p>
";
}
function returnArticleSearchSQL() {
// function for returning the output of a user's search query
// and output the results as clickable links
error_reporting(0); // briefly disable error checking,
//as one of these variables will always be unset, as the user can't search from both
$searchTerm = $_GET['headerSearchBar']; // get the contents of the headerSearchBar div on previous page
$searchTermMobile = $_GET['sideNavSearchBar'];
error_reporting(1); // re-enable
$hostname='localhost';
$username='unn_w15002812';
$password='RYNUZTYA';
$dbh = new PDO("mysql:host=$hostname;dbname=unn_w15002812",$username,$password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sqlQuery = "SELECT articleID, articleTitle, articleDate, articleAuth
FROM articles
WHERE articleTitle LIKE '%$searchTerm%'
ORDER BY articleDate DESC";
// retrieve articles where the article title contains part of the user's query
// % either side means their term could be anywhere within the title
$queryResult = $dbh->prepare($sqlQuery);
$queryResult->execute();
echo "<p class='searchQuery'>Articles containing: <strong>$searchTerm</strong></p>";
// echo out what the user's search term was
if ($dbh->query($sqlQuery)) {
while ($rowObj = $queryResult->fetchObject()) {
$eTitle = $rowObj->articleTitle;
$eAuthor = $rowObj->articleAuth;
$eDate = $rowObj->articleDate;
echo "<div class='searchedArticle'>
<a href='article.php?articleID={$rowObj->articleID}'<span class='searchedArticleTitle'>$eTitle</span></a>
<span class='searchedArticleDate'>$eDate</span>
<span class='searchedArticleAuthor'>$eAuthor</span>
</div>
";
}
}
$dbh = null;
}
function technologyFilterSQL() {
// this set of queries is to filter out content that isn't part of
// the respective category, i.e. this one will display all technology articles
$hostname='localhost';
$username='unn_w15002812';
$password='RYNUZTYA';
$dbh = new PDO("mysql:host=$hostname;dbname=unn_w15002812",$username,$password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sqlQuery = "SELECT articleID, articleTitle, articleDate, articleAuth, articleCat
FROM articles
WHERE articleCat = 'technology'
ORDER BY articleDate DESC";
// limit only to the technology category
// order by newest
$queryResult = $dbh->prepare($sqlQuery);
$queryResult->execute();
if ($dbh->query($sqlQuery)) {
while ($rowObj = $queryResult->fetchObject()) {
$eTitle = $rowObj->articleTitle;
$eAuthor = $rowObj->articleAuth;
$eDate = $rowObj->articleDate;
echo "<div class='searchedArticle'>
<a href='../article.php?articleID={$rowObj->articleID}'<span class='searchedArticleTitle'>$eTitle</span></a>
<span class='searchedArticleDate'>$eDate</span>
<span class='searchedArticleAuthor'>$eAuthor</span>
</div>
";
}
}
$dbh = null;
}
function entertainmentFilterSQL() {
$hostname='localhost';
$username='unn_w15002812';
$password='RYNUZTYA';
$dbh = new PDO("mysql:host=$hostname;dbname=unn_w15002812",$username,$password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sqlQuery = "SELECT articleID, articleTitle, articleDate, articleAuth, articleCat
FROM articles
WHERE articleCat = 'entertainment'
ORDER BY articleDate DESC";
$queryResult = $dbh->prepare($sqlQuery);
$queryResult->execute();
if ($dbh->query($sqlQuery)) {
while ($rowObj = $queryResult->fetchObject()) {
$eTitle = $rowObj->articleTitle;
$eAuthor = $rowObj->articleAuth;
$eDate = $rowObj->articleDate;
echo "<div class='searchedArticle'>
<a href='../article.php?articleID={$rowObj->articleID}'<span class='searchedArticleTitle'>$eTitle</span></a>
<span class='searchedArticleDate'>$eDate</span>
<span class='searchedArticleAuthor'>$eAuthor</span>
</div>
";
}
}
$dbh = null;
}
function fashionFilterSQL() {
$hostname='localhost';
$username='unn_w15002812';
$password='RYNUZTYA';
$dbh = new PDO("mysql:host=$hostname;dbname=unn_w15002812",$username,$password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sqlQuery = "SELECT articleID, articleTitle, articleDate, articleAuth, articleCat
FROM articles
WHERE articleCat = 'fashion'
ORDER BY articleDate DESC";
$queryResult = $dbh->prepare($sqlQuery);
$queryResult->execute();
if ($dbh->query($sqlQuery)) {
while ($rowObj = $queryResult->fetchObject()) {
$eTitle = $rowObj->articleTitle;
$eAuthor = $rowObj->articleAuth;
$eDate = $rowObj->articleDate;
echo "<div class='searchedArticle'>
<a href='../article.php?articleID={$rowObj->articleID}'<span class='searchedArticleTitle'>$eTitle</span></a>
<span class='searchedArticleDate'>$eDate</span>
<span class='searchedArticleAuthor'>$eAuthor</span>
</div>
";
}
}
$dbh = null;
}
function societyFilterSQL() {
$hostname='localhost';
$username='unn_w15002812';
$password='RYNUZTYA';
$dbh = new PDO("mysql:host=$hostname;dbname=unn_w15002812",$username,$password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sqlQuery = "SELECT articleID, articleTitle, articleDate, articleAuth, articleCat
FROM articles
WHERE articleCat = 'society'
ORDER BY articleDate DESC";
$queryResult = $dbh->prepare($sqlQuery);
$queryResult->execute();
if ($dbh->query($sqlQuery)) {
while ($rowObj = $queryResult->fetchObject()) {
$eTitle = $rowObj->articleTitle;
$eAuthor = $rowObj->articleAuth;
$eDate = $rowObj->articleDate;
echo "<div class='searchedArticle'>
<a href='../article.php?articleID={$rowObj->articleID}'<span class='searchedArticleTitle'>$eTitle</span></a>
<span class='searchedArticleDate'>$eDate</span>
<span class='searchedArticleAuthor'>$eAuthor</span>
</div>
";
}
}
$dbh = null;
}
function sportFilterSQL() {
$hostname='localhost';
$username='unn_w15002812';
$password='RYNUZTYA';
$dbh = new PDO("mysql:host=$hostname;dbname=unn_w15002812",$username,$password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sqlQuery = "SELECT articleID, articleTitle, articleDate, articleAuth, articleCat
FROM articles
WHERE articleCat = 'sport'
ORDER BY articleDate DESC";
$queryResult = $dbh->prepare($sqlQuery);
$queryResult->execute();
if ($dbh->query($sqlQuery)) {
while ($rowObj = $queryResult->fetchObject()) {
$eTitle = $rowObj->articleTitle;
$eAuthor = $rowObj->articleAuth;
$eDate = $rowObj->articleDate;
echo "<div class='searchedArticle'>
<a href='../article.php?articleID={$rowObj->articleID}'<span class='searchedArticleTitle'>$eTitle</span></a>
<span class='searchedArticleDate'>$eDate</span>
<span class='searchedArticleAuthor'>$eAuthor</span>
</div>
";
}
}
$dbh = null;
}
function politicsFilterSQL() {
$hostname='localhost';
$username='unn_w15002812';
$password='RYNUZTYA';
$dbh = new PDO("mysql:host=$hostname;dbname=unn_w15002812",$username,$password);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sqlQuery = "SELECT articleID, articleTitle, articleDate, articleAuth, articleCat
FROM articles
WHERE articleCat = 'politics'
ORDER BY articleDate DESC";
$queryResult = $dbh->prepare($sqlQuery);
$queryResult->execute();
if ($dbh->query($sqlQuery)) {
while ($rowObj = $queryResult->fetchObject()) {
$eTitle = $rowObj->articleTitle;
$eAuthor = $rowObj->articleAuth;
$eDate = $rowObj->articleDate;
echo "<div class='searchedArticle'>
<a href='../article.php?articleID={$rowObj->articleID}'<span class='searchedArticleTitle'>$eTitle</span></a>
<span class='searchedArticleDate'>$eDate</span>
<span class='searchedArticleAuthor'>$eAuthor</span>
</div>
";
}
}
$dbh = null;
}
?>