-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetcomments.php
47 lines (35 loc) · 1.05 KB
/
getcomments.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
<?php
require_once 'dbconfig.php';
$dbname = 'comments';
//define variables
try {
//connect to batabase
$pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
//echo "Connected to database $dbname at $host successfully. <br>";
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = ("SELECT comment_no, name, comment, entered ,publish
FROM comment
ORDER BY comment_no DESC");
$result = $pdo->query($sql);
}
//connection error
catch (PDOException $pe) {
die("Could not connect to the database $dbname :" . $pe->getMessage());
}
?>
<div id="container">
<h3>Comments left by others (un-moderated)</h3>
<table id = 'comments'>
<tbody>
<?php foreach ($result as $row) {
echo
"<tr> <td>".$row['comment'] . " <br/>
<span class='comments_small'>". $row[comment_no] . "-- Submitted by: ".$row['name']."
on ".$row['entered'] . "</span> <br> </td>
</tr>\n";
}
$pdo->close;
?>
</tbody>
</table>
</div>