SQL脚本的最新日期


SQL script with latest date

我正在开发一个发票视图系统,我想在iframe中查看单个PDF发票。我不知道如何制作SQL脚本,查看最新到期日的单个发票。

我正在使用Zend框架和数据库是MySQL。

    public function viewinvoiceemployeeAction()
{
    /** Object variable. Example use: $logger->err("Some error"); */
    $logger = Zend_Registry::get('LOGGER');
    /** Object variable. Example use: $something = $config->database; */
    $config = Zend_Registry::get('config');
    /** Object variable. Example use: print $date->get(); */
    $date = Zend_Registry::get('date');
    /** Object variable. Example use: $stmt = $db->query($sql); */
    $db = Zend_Registry::get('dbAdapter');
    $request = $this->getRequest();
          $id = (integer) $request->getParam('ostoreskontra_id');
          $dateColumn = (string) date("Y-m-d", strtotime("NOW"));
          //select * from yourTable where dateColumn = (select max(dateColumn) from yourTable)
          $db->beginTransaction();
          try {
              $date = (string) date("Y-m-d", strtotime($db->fetchone("SELECT laskun_pvm FROM ostoreskontra WHERE laskunera_pvm = (SELECT MAX(".$db->quote($dateColumn, 'STRING').") FROM ostoreskontra);")));
              $number = (integer) $db->fetchone("SELECT laskun_nro FROM ostoreskontra WHERE laskunera_pvm = (SELECT MAX(".$db->quote($dateColumn, 'STRING').") FROM ostoreskontra);");
              $sublier = (string) str_replace(" ","+",$db->fetchone("SELECT toimittaja.nimi FROM ostoreskontra LEFT JOIN toimittaja ON ostoreskontra.toimittaja_id=toimittaja.toimittaja_id WHERE ostoreskontra.laskunera_pvm = (SELECT MAX(".$db->quote($id, 'STRING').") FROM ostoreskontra);"));
              $file = (string) $date.'_'.$sublier.'_'.$number.'.pdf';
              $db->commit();
              $content = file_get_contents(APPLICATION_PATH."/uploads/ostolaskut/".$file);
              if ($id==0) {
                  header('Content-Type: text/plain');
              } else {
                  header('Content-Type: application/pdf');
                  header("Content-Length: " . strlen($content) );
                  //header('Content-Disposition: attachment; filename='.$file);
                  echo $content;
              }
          } catch (Exception $e) {
          $db->rollBack();
          //$success = array('success' => false, 'msg' => $e->getMessage());
          echo $e->getMessage();
          }
          //print_r($name);
}

你没有给我们太多信息,但是…使用此命令按日期获取表中的最后一条记录:

select * from yourTable where dateColumn = (select max(dateColumn) from yourTable)