-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharticles.php
More file actions
196 lines (176 loc) · 4.49 KB
/
articles.php
File metadata and controls
196 lines (176 loc) · 4.49 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
195
196
<?php
require_once 'db_connect.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Articles</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a:active {
text-decoration: none;
}
</style>
</head>
<body>
<div id="contain">
<div id="header">
<h1><?php echo "$sitename";?></h1>
</div>
<div id="menus">
<a href="index.php" target="_self">Home</a>
<?php
/*
Displaying List of Categories from the Table - Category and that is limited to 6
*/
$qry=mysql_query("SELECT * FROM category LIMIT 0, 6", $con);
if(!$qry)
{
die("Query Failed: ". mysql_error());
}
/* Fetching datas from the field "category" and article id is transfered to articles.php file */
while($row=mysql_fetch_array($qry))
{
echo " <a href=articles.php?cat=".$row['category'].">".$row['category']."</a> ";
}
?>
</div>
<div id="l_space">
<h2>Blog in this Categoy::</h2>
<?php
/*
isset() is used to check wheather arctile id is received through url from "index.php" file and if it is set corresponding arctile is displayted using SELECT statement.
*/
if(isset($_GET['id']))
{
$id=$_GET['id'];
$qry=mysql_query("SELECT * FROM articles WHERE id=$id", $con);
if(!$qry)
{
die("Query Failed: ". mysql_error());
}
/* Fetching data from the field "title" */
while($row=mysql_fetch_array($qry))
{
echo "<h2>".$row['title']."</h2>";
echo "<img src=".$row['image']." />";
echo "<p>".$row['contents']."</p>";
}
echo "<h2>Comments</h2>";
}
/*
based on the category name received from index.php file the last added article is displayed
*/
if(isset($_GET['cat']))
{
//echo $_GET['cat'];
$cat=$_GET['cat'];
$qry=mysql_query("SELECT * FROM articles WHERE category='$cat' order by articles.id DESC LIMIT 0, 5", $con);
if(!$qry)
{
die("Query Failed: ". mysql_error());
}
/* Fetching data from the field "title" */
while($row=mysql_fetch_array($qry))
{
echo "<h2>".$row['title']."</h2>";
echo "<img src=".$row['image']." />";
echo "<p>".$row['contents']."</p>";
echo "<p>".substr($row['contents'],0,0)."<a href=articles.php?id=".$row['id']." > See Article..</a></p>";
}
}
?>
<form action='comment.php?id=<?php echo $id ?>' method='post'>
<?php
if(isset($_GET['id']))
{
echo "<textarea name='comment' cols='50' rows='3' id='comment'></textarea>";
echo "</br>";
echo "<input type='submit' value='Submit' />";
}
?>
</form>
<?php
if(isset($_GET['id']))
{
$id=$_GET['id'];
$qry=mysql_query("SELECT * FROM comments WHERE cmnt_id='$id' order by comments.cmnt_id ASC", $con);
if(!$qry)
{
die("Query Failed: ". mysql_error());
}
/* Fetching data from the field "title" */
while($row=mysql_fetch_array($qry))
{
echo "</br>_______________________________________________________________</br>";
echo "<b>Commented on : ".$row['comment_dt']."</b></br></br>";
echo $row['comment'];
}
}
?>
<br>
<br><br>
</div>
<div id="r_space">
<h2>List in this Category</h2>
<?php
/*
based on the id received from index.php through url, the category of the particular article is determined
*/
if(isset($_GET['id']))
{
$id=$_GET['id'];
$qry=mysql_query("SELECT category FROM articles WHERE id='$id'", $con);
if(!$qry)
{
die("Query Failed: ". mysql_error());
}
/* Fetching data from the field "title" */
$row=mysql_fetch_array($qry);
$cat=$row['category'];
/*
once the category of the article is determined this section is used to display the title of all the articles belonging to that category
*/
$qry=mysql_query("SELECT * FROM articles WHERE category='$cat' order by articles.id DESC", $con);
if(!$qry)
{
die("Query Failed: ". mysql_error());
}
while($row=mysql_fetch_array($qry))
{
//echo $row['title'];
echo "<li><a href=articles.php?id=".$row['id'].">".$row['title']."</a></li>";
}
}
/*
based on the category name received from index.php file title names of all the articles belong to the category is displayed with hyperlinks
*/
if(isset($_GET['cat']))
{
$cat=$_GET['cat'];
$qry=mysql_query("SELECT * FROM articles WHERE category='$cat' order by articles.id DESC", $con);
if(!$qry)
{
die("Query Failed: ". mysql_error());
}
while($row=mysql_fetch_array($qry))
{
echo "<li><a href=articles.php?id=".$row['id'].">".$row['title']."</a></li>";
}
}
?>
</div>
<div id="footer">
<div align="center"><strong>Powered by Blogin!!! @ 2012</strong></div>
<br>
</body>
</html>