Alter the table and add a timestamp:
ALTER TABLE Posts ADD postDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
Then order and limit by postDate
:
SELECT post FROM Posts ORDER BY postDate DESC LIMIT 2
Iterate through the results and echo out the post
inside the textarea
tag.
IMPORTANT
mysql_* functions are deprecated, and should no longer be used. Look into mysqli or PDO.
Also, use htmlentities()
with $_SERVER['PHP_SELF']
to protect against XSS. See this question for more info.
An example using mysqli
:
//I usually put the connection in a separate file, and include it as needed
$mysqli = mysqli_connect("myhost","myuser","mypassw","mydb") or die("Error " . mysqli_error($mysqli));
$stmt = $mysqli->prepare("SELECT post FROM Posts ORDER BY postDate LIMIT 2");
$stmt->execute();
$stmt->bind_result($post);
while($stmt->fetch()) {
$post = htmlentities($post, ENT_QUOTES, "UTF-8");
echo "<textarea rows='12' cols='60' spellcheck='false'>$post</textarea> <br/>";
}