-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblog_getPostIDsFromDB.php
105 lines (83 loc) · 3.04 KB
/
blog_getPostIDsFromDB.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
<?PHP
//Hämtar alla ostidn för en specifik blogg från databasen
session_start();
$blogID = $_SESSION["blogID"];
require_once("blog_db.php");
$db=new DB();
$postIDs = "§";
$postIDsDates = "§";
$postTitles = "§";
$postSource = "§";
$SQL = "SELECT postID, postTitle, source FROM post WHERE blogID=$blogID ORDER BY postID DESC";
$matrix = $db->getData($SQL);
for($i = 0; $i<count($matrix); $i++) {
$oldID = $matrix[$i][0];
$newID = $matrix[$i][0];
$SQL = "SELECT newID FROM postversion WHERE oldID = ".$matrix[$i][0]."";
//echo($SQL);
$newIDCheck = $db->getData($SQL);
if(!isset($newIDCheck[0][0]))
{
$SQL = "SELECT oldID FROM postversion WHERE newID = $newID";
//echo($SQL);
$oldIDMatrixCheck = $db->getData($SQL);
//echo($oldIDMatrixCheck[0][0]);
if(isset($oldIDMatrixCheck[0][0]))
{
$counter = 0;
while($counter<2)
{
$SQL = "SELECT oldID FROM postversion WHERE newID = $newID";
$oldIDMatrix = $db->getData($SQL);
if(isset($oldIDMatrix[0][0]))
{
$newID = $oldIDMatrix[0][0];
$counter = 0;
}
$counter++;
}
}
$finalIDDate = $newID;
}
else
{
$finalIDDate = null;
$oldID = null;
}
if(isset($oldID))
{
$postIDs = $postIDs."&".$oldID;
$postIDsDates = $postIDsDates."&".$finalIDDate;
}
}
$postFirstIDsArray = explode("&", $postIDsDates);
$postCurrentIDsArray = explode("&", $postIDs);
$temp="";
for($j = 0; $j<count($postFirstIDsArray); $j++) {
for($k = 0; $k<(count($postFirstIDsArray)-($j+1)); $k++) {
if($postFirstIDsArray[$k]<$postFirstIDsArray[$k+1]) {
$temp = $postFirstIDsArray[$k+1];
$postFirstIDsArray[$k+1] = $postFirstIDsArray[$k];
$postFirstIDsArray[$k] = $temp;
$temp = $postCurrentIDsArray[$k+1];
$postCurrentIDsArray[$k+1] = $postCurrentIDsArray[$k];
$postCurrentIDsArray[$k] = $temp;
}
}
}
$postIDs = "§";
$postTitles = "§";
$postSource = "§";
for($i = 1; $i<count($postCurrentIDsArray); $i++)
{
//echo($postCurrentIDsArray[$i]."\n");
$SQL = "SELECT postID, postTitle, source FROM post WHERE postID=".$postCurrentIDsArray[$i]."";
//echo($SQL);
$matrix = $db->getData($SQL);
$postIDs = $postIDs."&".$matrix[0][0];
$postTitles = $postTitles."&".$matrix[0][1];
$postSource = $postSource."&".$matrix[0][2];
}
$data = $postIDs.$postTitles.$postSource;
echo($data);
?>