Hi, Sorry if this is infantile, I'm a noob..
I'm trying to write a sort of "event list" for my dad's website and I can't figure out what kind of function I need to include in the code that would select or display only table rows that occur after today's date.
Does anybody have or know where I can find insight into this that would help me complete this?
The question is not infantile at all and the answer has some subtleties that can lead to interesting insights. The difference between a date and datestamp, for example... but you'll discover that as you go along. To get you started, though, you do the hard part in the selection statement like this:
Code:
…
$link = mysql_connect($host, $user, $password) or die(“Could not connect to database: ” . mysql_error());
mysql_select_db($dbtable, $link) or die('Uh oh...' . mysql_error());
$query = “SELECT * FROM table WHERE date>'$startdate' AND date<'$enddate'”;
// Uncomment the next line if you run into problems that don't generate an error - your query may not look like you think it does
// echo "$query<br />";
$result = mysql_query($query);
if ($result === FALSE) die('Whoopsie: ' . mysql_error());
while (($thegoodstuff = mysql_fetch_assoc($result)) !== FALSE) {
echo “$thegoodstuff['date'], $thegoodstuff['anotherfield'], $thegoodstuff['etc']<br />”;
}
lol... you sent the second message while I was still composing mine... anyway, check the comment in the middle of my code (seeing your query often resolves the problem)
Wow, I've never thought of that.. that's awesome.. I'm definetly going to use that a lot from now on.. I'm still working through this code, I'll report back here after a bit.. After looking at your code, I think I see where I'm going wrong..
Glad to hear you worked it out & glad I could help. Printing out intermediate results is a real time saver in debugging. The more you do it, the more you will recognize its value.
Bookmarks