Jump to content


Php and my sql dates

  • Please log in to reply
4 replies to this topic

#1 webezine

  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 28 February 2006 - 12:18 PM

Hi all.
Really need some help with this! I have an events database where event details are stored. The date is stored in teh format yyyy/mm/dd. I have a script that reads all events from the database and echos them out onto a new sheet. Thing is I need it only to display 2 weeks worth of event... meaning showing all events taht take ;place within the next 2 weeks from the curretn date. The current script i ahve is:

$conn = mysql_connect();
$counter =0;
$result = mysql_query("SELECT * FROM events ORDER BY eventdate");
while($row = mysql_fetch_array($result))
if ($counter>0){
echo"<p> The following event take place within the next 2 weeks:</p><table>";
echo "<tr><td colspan='4'><hr></hr></td></tr>";
$result = mysql_query("SELECT * FROM events ORDER BY Eventdate");
while($row = mysql_fetch_array($result))
echo "<tr><td><em>Name: </em> $row[name]</td>";
echo "<td><em>Date (yyyy-mm-dd): </em> $row[eventdate]</td>";
echo "<td><em>Tickets: </em> $row[maxtickets]</td>";
echo "<td><em>Price: </em> $row[price]</td>";
echo "</tr><tr><td colspan='1'><em>Tickets remaining: </em> $row[remintickets]</td>";
echo "<td colspan='3'><em>Description: </em> $row[description]</td></tr>";
echo "<tr><td colspan='4'><hr></hr></td></tr>";

This works but just need some help to load only 2 weeks worth of stuff. PLEASE HELP!
If you have any ideas please e-mail me @ webezine 'at' hotmail.co.uk

#2 litebearer

  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 28 February 2006 - 04:29 PM

Here is some info regarding using mysql's date functions. With a little tweaking it will accomplish what you need.

[a href=\"http://www.devshed.com/c/a/MySQL/Date-Arithmetic-With-MySQL/3/\" target=\"_blank\"]http://www.devshed.com/c/a/MySQL/Date-Arit...c-With-MySQL/3/[/a]


all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

#3 shocker-z

  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 28 February 2006 - 05:51 PM

i personaly would use:

www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#4 kenrbnsn

  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 28 February 2006 - 06:06 PM

Change how the field is defined in MySQL to be of the type "date", then you can use the query as posted by shocker-z.


#5 webezine

  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 06 March 2006 - 02:47 AM

Shocker if this works I LOVE YA!

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users