Hi guys, I'm new to PHP and MySQL and I have a question.
I am trying to create a weblog that will only show the past three days entries. I have used a timestamp on the insert page, but cannot get it to only show me the past three days entries on the weblog page.
It's a simple setup so far, two pages(addentry.php and weblog.php), one database(weblog) with three tables.
This is the MySQL code I used to create the tables:
CREATE TABLE weblog (
entrydate TIMESTAMP PRIMARY KEY,
entrytitle VARCHAR(100),
entrytext TEXT);
This is my entry page, addentry.php:
<HTML>
<HEAD>
<TITLE>Prayer Request Entry</TITLE>
</HEAD>
<body background="http://www.mttopmin.org/images/bkgnd_main.jpg" style="background-attachment: fixed;" bgproperties="fixed">
<?php
if ($HTTP_POST_VARS['submit']) {
mysql_connect("localhost","my_username","my_password");
mysql_select_db("ronparr_prayer");
$entrytitle=$HTTP_POST_VARS['entrytitle'];
$entrytext=$HTTP_POST_VARS['entrytext'];
$query ="INSERT INTO weblog (entrytitle,entrytext)";
$query.=" VALUES ('$entrytitle','$entrytext')";
$result=mysql_query($query);
if ($result) echo "<b>Successfully Posted!</b>";
else echo "<b>ERROR: unable to post.</b>";
}
?>
<H1>Prayer Request</H1>
<form method="POST" action="addentry.php">
<b>Title:</b><br>
<input type="text" name="entrytitle"><br>
<b>Weblog Entry:</b><br>
<textarea cols="60" rows="6" name="entrytext">
</textarea><br>
<input type="submit" name="submit" value="Submit">
</form>
</BODY>
</HTML>
This is the display page, weblog.php:
<html>
<head><title>Prayer Requests</title></head>
<body background="http://www.mttopmin.org/images/bkgnd_main.jpg" style="background-attachment: fixed;" bgproperties="fixed">
<h1>Prayer Requests</h1>
<dl>
<?php
mysql_connect("localhost","my_username","my_password");
mysql_select_db("ronparr_prayer");
$query ="SELECT entrytitle, entrytext,";
$query.=" DATE_FORMAT(entrydate, '%M %d, %Y @ %h:%i:%s') AS date";
$query.=" FROM weblog ORDER BY entrydate DESC LIMIT 10";
$result=mysql_query($query);
while (list($entrytitle,$entrytext,$entrydate) =
mysql_fetch_row($result)) {
echo "<dt><b>$entrytitle ($entrydate)</b></dt>";
echo "<dd>$entrytext</dd><br><hr><br>";
}
?>
</dl>
</body>
</html>
Can someone please help me? I only want the display page to show the past three days. I know it's something simple, but like I said, I am new to this and I'm making everything harder than it needs to be.
Thanks in advance for all your help.