Need help with structure
Posted: Wed Jan 28, 2004 8:31 pm
Code: Select all
<?php
<?
include("mysql.php");
include("header.php");
echo "<div align="center">"
."<form action="{$_SERVER['PHP_SELF']}"\n"
."<p>Type your Date here: eg. 2004-01-31 (y-m-d)<br/>\n"
."<input type="text" name="date" cols="40"><br>\n"
."<p>Is this Upcoming or Past eg. Upcoming OR Past<br/>\n"
."<input type="text" name="uppast" cols="40"><br>\n"
."<p>Please enter the filename of the flyer eg. flyer24.jpg<br/>\n"
."<input type="text" name="pic" cols="40"><br>\n"
."<p>Type your Description here here:<br/>\n"
."<textarea name="desc" rows="10" cols="40" wrap></textarea><br/>\n"
."<input type="submit" name="submitevents" value="SUBMIT" /></p>\n"
."</form>\n"
."</div>";
echo "<div align="center"><strong>NOTE - </strong>To go to the next line type in < br > (without the spaces between < ) </div><br><br>";
//adding to the database
if ($submitevents == "SUBMIT") {
$sql = "INSERT INTO events SET date='$date', `desc`='$desc', `location`='$location', `pic`='$pic'";
if (@mysql_query($sql)) {
echo("<div align="center">Your Event has been added.<br></div>");
} else {
echo ("<div align="center">Error adding submitted Event: " . mysql_error() . "</div>");
}
}
//deleting from the database
if (isset($deleteevents)) {
$sql = "DELETE FROM events WHERE id=$deleteevent";
if (@mysql_query($sql)) {
echo("<div align="center">The event has been deleted.</div>");
}else{
echo("<p>Error deleting event: " . mysql_error() . "</p>");
}
}
//preparing data from database
$result = @mysql_query("SELECT * FROM events ORDER BY `date` ");
while ($row = mysql_fetch_array($result)) {
$newdate = explode("-",$row["date"]);
$month = $newdate[1]; // eg. February
$day = $newdate[2]; // eg. 04
$year = $newdate[0]; // eg. 2004
$id = $row["id"];
$desc = $row["desc"];
$pic = $row["pic"];
$date = $row["date"];
if ($month == "01") {
$month2="January";
}elseif ($month == "02") {
$month2="Febuary";
}elseif ($month == "03") {
$month2="March";
}elseif ($month == "04") {
$month2="April";
}elseif ($month == "05") {
$month2="May";
}elseif ($month == "06") {
$month2="June";
}elseif ($month == "07") {
$month2="July";
}elseif ($month == "08") {
$month2="August";
}elseif ($month == "09") {
$month2="September";
}elseif ($month == "10") {
$month2="October";
}elseif ($month == "11") {
$month2="November";
}else{
$month2="December";
}
echo "<table width="668" border="0" cellpadding="0" cellspacing="0">\n"
."<tr>\n"
."<td width="22%" height="20">Date</td>\n"
."<td width="26%">Description</td>\n"
."<td width="32%">Location</td>\n"
."<td width="20%">Flyer</td>\n"
."</tr>\n"
."<tr>\n"
."<td width="22%" height="20">".$month2."-".$year."</td>\n"
."<td width="26%">".$desc."</td>\n"
."<td width="32%">".$location."</td>\n"
."<td width="20%">\n";
if ($pic==""){
echo "<img src="http://www.*********.com/events_files/images/flyer_not.jpg" width="100" height="58">\n";
}else{
echo "<img src="http://www.*********.com/events_files/images/$pic.jpg" width="100" height="58">\n";
}
echo "</td>\n"
."</tr>\n"
."</table>\n"
."<br>\n";
}
?>
?>UPCOMING EVENTS
EVENT 1
DATE - DESCRIPTION - LOCATION - FLYER
EVENT 2
DATE - DESCRIPTION - LOCATION - FLYER
PAST EVENTS
EVENT 1
DATE - DESCRIPTION - LOCATION - FLYER
EVENT 2
DATE - DESCRIPTION - LOCATION - FLYER
My problem is not with the coding, it's figuring out how to set this all up. I have the events outputting properly, but I can't figure out how to make the past and upcoming events seperate while keeping them in order of date.
I was thinking about doing it like this..
in my loop, adding something like
Code: Select all
<?php
$current_date = date('Y-m-d');
if ($current_date > $date) {
echo "Current date";
}else{
echo "Past date";
?>*lol* I just thought of a possiblity... I'll post my results soon.. but please post your ideas.. they are most likely better than mine