Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- $username = $_SESSION['name'];
- $db = pg_connect("host=127.0.0.1 dbname=Verkefni5a user=postgres password=xxxxx");
- $result = pg_query($db, "SELECT m.timestamp, message
- FROM messages m, users u
- WHERE username='" . $username . "' AND m.userid=u.id
- ORDER BY m.timestamp DESC LIMIT 5");
- $friend_result = pg_query($db, "Select username, timestamp, message
- FROM users INNER JOIN
- (
- (SELECT userid, timestamp, message
- FROM messages INNER JOIN
- (
- SELECT following
- FROM follows
- WHERE userid =
- (SELECT id from users
- WHERE username = '" . $username . "')
- ) AS foo
- ON messages.userid=foo.following)
- ) AS foo2
- ON users.id = foo2.userid
- ORDER BY timestamp DESC LIMIT 20");
- ?>
- <html>
- <head>
- <title>Welcome<?php echo " " . $username . "!"; ?></title>
- </head>
- <body>
- <?php
- echo "<h1>Welcome " . $username . "!</h1>\n";
- echo "Your latest posts:<br>";
- echo "<table border=\"1\" cellpaddin=\"2\" cellspacing=\"2\">";
- echo "<tr>";
- echo "<td>Date and time</td>";
- echo "<td>Messages</td>";
- echo "</tr>";
- while ($row = pg_fetch_assoc($result))
- {
- print '<tr>';
- print '<td>' . $row['timestamp'] . '</td>';
- print '<td>' . $row['message'] . '</td>';
- print '</tr>';
- }
- echo "</table>";
- ?>
- <br /><b>Have something to say?</b><br />
- <form name="input" action="update.php" method="POST">
- <label>Message: </label><input type="text" name="update" />
- <input type="submit" value="Submit" />
- </form>
- <br /><b>Want to see what someone else is saying? Write his/her name here!</b><br />
- <form name="input" action="view.php" method="GET">
- <label>Username: </label><input type="text" name="username" />
- <input type="submit" value="Submit" />
- </form>
- <br /><b>Those that you are following are saying this: </b><br />
- <?php
- echo "<table border=\"1\" cellpaddin=\"2\" cellspacing=\"2\">";
- echo "<tr>";
- echo "<td>Username</td>";
- echo "<td>Messages</td>";
- echo "<td>Date and time</td>";
- echo "</tr>";
- while ($row = pg_fetch_assoc($friend_result))
- {
- print '<tr>';
- print '<td>' . $row['username'] . '</td>';
- print '<td>' . $row['message'] . '</td>';
- print '<td>' . $row['timestamp'] . '</td>';
- print '</tr>';
- }
- echo "</table>";
- ?>
- <p />Log out:<input type="button" onclick="self.location='logout.php'" value="HERE!" />
- </body>
- </html>
- }
- else
Add Comment
Please, Sign In to add comment