-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdbfetch.php
More file actions
80 lines (72 loc) · 3.32 KB
/
dbfetch.php
File metadata and controls
80 lines (72 loc) · 3.32 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
<?php
require "dbconnection.php";
function fetch_twitter_items($currentLimit, $limit) {
global $mysql;
$query = 'SELECT SUBSTRING(text, 1, 250), retweets, id FROM twitter_posts GROUP BY text ORDER BY likes DESC LIMIT '. $currentLimit .',' .$limit.' ';
$stmt = $mysql->prepare($query);
$stmt->execute();
$result = $stmt->get_result();
return $result;
}
function display_twitter_items($currentLimit) {
$result = fetch_twitter_items($currentLimit, 12);
while ($row = $result->fetch_assoc()) {
echo '<div class="twitter_post">';
echo ' <a class="post" id="'.$row['id'].'" href="twitterpost.php?id='.$row['id'].'">';
echo ' <h3> </h3>';
echo ' <p class="description">'.$row['SUBSTRING(text, 1, 250)'] . '...' . '</p>';
echo ' </a>';
echo '</div>';
}
}
function fetch_reddit_items($currentLimit, $limit) {
global $mysql;
$query = 'SELECT title, SUBSTRING(selftext, 1, 250), score, id FROM reddit_posts WHERE selftext IS NOT NULL ORDER BY score DESC LIMIT '. $currentLimit .',' .$limit.' ';
$stmt = $mysql->prepare($query);
$stmt->execute();
$result = $stmt->get_result();
return $result;
}
function display_reddit_items($currentLimit) {
$result = fetch_reddit_items($currentLimit, 12);
while ($row = $result->fetch_assoc()) {
echo '<div class="reddit_post">';
echo ' <a class="post" id="<'.$row['id'].'" href="redditpost.php?id='.$row['id'].'">';
echo ' <h3 class="title">'.$row['title'].' </h3>';
echo ' <p class="description">'.$row['SUBSTRING(selftext, 1, 250)'] . '...' . '</p>';
echo ' </a>';
echo '</div>';
}
}
function fetch_youtube_items($currentLimit, $limit) {
global $mysql;
$query = 'SELECT title, link, thumbnail, score FROM youtube_videos WHERE description IS NOT NULL ORDER BY score DESC LIMIT '. $currentLimit .',' .$limit.' ';
$stmt = $mysql->prepare($query);
$stmt->execute();
$result = $stmt->get_result();
return $result;
}
function display_youtube_items($currentLimit) {
$result = fetch_youtube_items($currentLimit, 12);
while ($row = $result->fetch_assoc()) {
echo '<div class="youtube_post">';
echo ' <a class="post" href="'.$row['link'].'" target="_blank">';
echo ' <h3 class="title"> '.$row['title'].' </h3>';
echo ' <div class="for_image">';
echo ' <img class="youtube_image" src="'.$row['thumbnail'].'">';
echo ' </div>';
echo ' </a>';
echo '</div>';
}
}
if(array_key_exists('seemoretwitter', $_GET)) {
$currentLimit = (int)$_GET['seemoretwitter'];
display_twitter_items($currentLimit);
} else if(array_key_exists('seemorereddit', $_GET)) {
$currentLimit = (int)$_GET['seemorereddit'];
display_reddit_items($currentLimit);
} else if(array_key_exists('seemoreyoutube', $_GET)) {
$currentLimit = (int)$_GET['seemoreyoutube'];
display_youtube_items($currentLimit);
}
?>