-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScripturesDB.php
112 lines (103 loc) · 2.77 KB
/
ScripturesDB.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
<?php
function test() {
$server = getenv('OPENSHIFT_MYSQL_DB_HOST');
$database = 'scriptures';
$username = getenv('OPENSHIFT_MYSQL_DB_USERNAME');
$password = getenv('OPENSHIFT_MYSQL_DB_PASSWORD');
$dsn = 'mysql:host='.$server.';dbname='.$database;
try{
$g1db = new PDO($dsn, $username, $password);
return $g1db;
}
catch (PDOException $ex){
echo 'Error!:' . $ex->getMessage();
die();
}
}
$test = test();
function viewScriptures() {
global $test;
$query = 'SELECT scriptures.scripture_id, scriptures.chapter, scriptures.verse, scriptures.content, books.name
FROM scriptures
INNER JOIN books
ON scriptures.book_id = books.book_id
ORDER BY books.name';
$statement = $test->prepare($query);
$statement->execute();
$scriptures = $statement->fetchAll();
$statement->closeCursor();
return $scriptures;
}
function findTopicByScripture($scripture){
global $test;
$query = 'SELECT link.topic_id, topics.topic_name FROM link
INNER JOIN topics
ON link.topic_id = topics.topic_id
WHERE link.scripture_id ='. $scripture;
$statement = $test->prepare($query);
$statement->execute();
$topics = $statement->fetchAll();
$statement->closeCursor();
return $topics;
}
function viewScripturesByBook($book_id = "-1") {
global $test;
if ($book_id == "-1") {
$scriptures = viewScriptures();
} else {
$query = 'SELECT scriptures.scripture_id, scriptures.chapter, scriptures.verse, scriptures.content, books.name
FROM scriptures
INNER JOIN books
ON scriptures.book_id = books.book_id
WHERE scriptures.book_id = :book_id
ORDER BY books.name';
$statement = $test->prepare($query);
$statement->bindValue(":book_id", $book_id);
$statement->execute();
$scriptures = $statement->fetchAll();
$statement->closeCursor();
}
return $scriptures;
}
$book = filter_input(INPUT_POST, 'book');
if (!isset($book) || $book == "all"){
$scriptures = viewScriptures();
} else {
$scriptures = viewScripturesByBook($book);
}
?>
<article>
<h1>Scripture Resources</h1>
<ul>
<?php foreach ($scriptures as $scripture): ?>
<li>
<strong>
<?php echo $scripture['name']; ?>
<?php echo $scripture['chapter']; ?>:
<?php echo $scripture['verse']; ?>
</strong>
- <?php echo $scripture['content']; ?>
<strong>
<?php
//echo $scripture['scripture_id'];
$scripture_temp = $scripture['scripture_id'];
$topics = findTopicByScripture($scripture_temp);
//print_r($topics);
foreach($topics as $topic){
echo $topic['topic_name'] . " ";
}
?>
</strong>
</li>
<?php endforeach; ?>
</ul>
</article>
<article>
<BODY>
<center>
<a href="search_scripture.php"><h3>View Scriptures</h3></a>
<a href="scriptureInsert.php"><h3>Add a scripture</h3></a>
<a href="index.html"><h3>Home</h3></a>
</center>
</BODY>
</article>