Author Topic: SQL Query for retrieving todays date  (Read 2227 times)

0 Members and 1 Guest are viewing this topic.

Offline bobicles2Topic starter

  • Irregular
  • Posts: 37
    • View Profile
SQL Query for retrieving todays date
« on: February 03, 2010, 02:22:35 PM »
I have this code

Quote
<?php
            $sql="select * from Events where issue = (select max(issue) from jfs);";
         
            $result_set = pg_Exec ($conn, $sql);
            $rows = pg_NumRows($result_set);

            if ((!$result_set) || ($rows < 1)) {
                  echo "<H1>ERROR - no rows returned</H1><P>";
                  exit;  //exit the script
                  }

            $previous_issue = "";
            for ($j=0; $j < $rows; $j++)
               {
               $issue = pg_result($result_set, $j, "issue");
$page = pg_result($result_set, $j, "page");
               $author = pg_result($result_set, $j, "author");
               
               $title = pg_result($result_set, $j, "title");

               $url = pg_result($result_set, $j, "url");
         
?>

That pulls up "todays issue" from the table...but im looking to change it so that it pulls up items in the database with todays date.

i.e - an issue with the date 15/02/10 would be displayed on the screen on that date only...

Quote
  $sql="select * from Events where issue = (select max(issue) from jfs);";

i know its the above part i need to alter but im not really sure how :( If anyone has any other advice id be grateful im doing this for a school project so im aware its very basic but i honestly appreciate all advice as for me its all part of the learning curve and im keen to improve!


Thanks in advance
Rob


Offline dmikester1

  • Enthusiast
  • Posts: 69
    • View Profile
Re: SQL Query for retrieving todays date
« Reply #1 on: February 03, 2010, 02:38:43 PM »
Is issue a "date" in your database?  Are you storing a date in the database for each issue?

Offline Mchl

  • Staff Alumni
  • Freak!
  • *
  • Posts: 8,582
  • Gender: Male
  • That's Largo in my avatar, not me.
    • View Profile
    • FlingBits
NetBeans fanatic | ExtJS masochist | C++ denier
PHP4 & MySQL4 are no longer supported.
PHPFreaks Tutorials | PHP Debugging: A Beginner's guide | PHP Security Tutorial || How To Ask Questions The Smart Way
Flingbits tutorials | Class Autoloading

Offline bobicles2Topic starter

  • Irregular
  • Posts: 37
    • View Profile
Re: SQL Query for retrieving todays date
« Reply #3 on: February 03, 2010, 02:57:37 PM »
issue us a varchar not date in my table....however, i can easily change i just used varchar to test my database was working!

im not sure what date input is....is it 00/00/00? or like 00/00/0000?



thanks
rob

Offline dmikester1

  • Enthusiast
  • Posts: 69
    • View Profile
Re: SQL Query for retrieving todays date
« Reply #4 on: February 03, 2010, 03:06:42 PM »
Well, you need to get today's date using PHP's Date function. http://php.net/manual/en/function.date.php  Then do a "select issue from database" making sure the two dates are in the same format and compare for equality.

Mike

Offline bobicles2Topic starter

  • Irregular
  • Posts: 37
    • View Profile
Re: SQL Query for retrieving todays date
« Reply #5 on: February 03, 2010, 03:33:14 PM »
got it working using

CURRENT_DATE

just need to alter the html part now so the form input can only be in format 0000-00-00 so this doesnt mess up!

thanks for all the help guys! this forum never lets me down :D!
« Last Edit: February 03, 2010, 03:42:40 PM by bobicles2 »

Offline bobicles2Topic starter

  • Irregular
  • Posts: 37
    • View Profile
Re: SQL Query for retrieving todays date
« Reply #6 on: February 03, 2010, 03:47:37 PM »
Now to find the HTML Form information...

not sure if it exists sad times!

Offline dmikester1

  • Enthusiast
  • Posts: 69
    • View Profile
Re: SQL Query for retrieving todays date
« Reply #7 on: February 03, 2010, 03:47:50 PM »
I don't know if you know any JQuery, but JQuery's Datepicker is wonderful for this sort of thing.  And you can of course change the format of the date in the options.  Check it out. http://jqueryui.com/demos/datepicker/
Mike