php

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • kirke

    php

    Help me guys. I have several problems in following code :

    SQL query code doesn't work. I connect to My SQL Server. and
    'StartDate' is the name of textbox. it forms 07/10/2006
    Thus, I receive two dates as $StartD and $EndD.

    Original dtDateTime looks like 07/10/2006 11:23:44
    I want to select only between $StartD and $EndD. However
    = WHERE dtDateTime Between ' $StartD ' AND ' $EndD '
    doesn't work.

    Second problem is
    =DISTINCT(LEFT( dtDateTime,9)) As NewD
    'dtDateTime' has time data, but i wanna only date. Thus, i select
    LEFT(~,9) (it also have problem when month and date both have two
    numbers (11/22/2006) but i have no idea except LEFT commend)
    Also I want to use DISTINCT. and put the list of distinct dates in
    drop-down box.

    So i use
    => echo '<option value="'.$row['NewD'].'">'.$row['NewD'].'</option>';
    Also this part doesn't work.

    Another question is,
    in form, can I assign multiple pages as action page?
    Or there's other way to use values in non-action page?


    Following is whole code.
    Thank you!!!!!!!!




    $StartD=(int)$_ POST['StartDate'];
    $EndD=(int)$_PO ST['EndDate'];


    <?php
    $sql = "SELECT DISTINCT(LEFT(d tDateTime,9)) As NewD FROM dbo_J1708Data
    WHERE (dtDateTime Between ' $StartD ' AND ' $EndD ' )";

    $result= mysql_query($sq l) or die();
    ?>


    <form id="form1" name="form1" method="post" action="result. php">

    <table>
    <tr>
    <td width="83" height="27">Tim e Series:</td>
    <td width="105">
    <select name="TS" id="TS">
    <?php
    while( $row = mysql_fetch_arr ay($result) )
    {
    echo '<option value="'.$row['NewD'].'">'.$row['NewD'].'</option>';
    }
    ?>
    </select></td </tr</table>

  • Gordon Burditt

    #2
    Re: php

    >SQL query code doesn't work. I connect to My SQL Server. and
    >'StartDate' is the name of textbox. it forms 07/10/2006
    >Thus, I receive two dates as $StartD and $EndD.
    07/10/2006 is NOT the date format that MySQL uses. MySQL wants
    2006-07-10 or 2006-10-07, depending on what country's date format
    07/10/2006 is intended to be.

    If you wish to convert TO MySQL's date format, try str_to_date().
    If you wish to convert FROM MySQL's date format to some other format,
    try date_format().


    Comment

    • Colin Fine

      #3
      Re: php

      kirke wrote:
      Help me guys. I have several problems in following code :
      >
      SQL query code doesn't work. I connect to My SQL Server. and
      'StartDate' is the name of textbox. it forms 07/10/2006
      Thus, I receive two dates as $StartD and $EndD.
      >
      Original dtDateTime looks like 07/10/2006 11:23:44
      I want to select only between $StartD and $EndD. However
      = WHERE dtDateTime Between ' $StartD ' AND ' $EndD '
      doesn't work.
      >
      Second problem is
      =DISTINCT(LEFT( dtDateTime,9)) As NewD
      'dtDateTime' has time data, but i wanna only date. Thus, i select
      LEFT(~,9) (it also have problem when month and date both have two
      numbers (11/22/2006) but i have no idea except LEFT commend)
      Also I want to use DISTINCT. and put the list of distinct dates in
      drop-down box.
      >
      So i use
      => echo '<option value="'.$row['NewD'].'">'.$row['NewD'].'</option>';
      Also this part doesn't work.
      >
      Another question is,
      in form, can I assign multiple pages as action page?
      Or there's other way to use values in non-action page?
      >
      >
      Following is whole code.
      Thank you!!!!!!!!
      >
      >
      >
      >
      $StartD=(int)$_ POST['StartDate'];
      $EndD=(int)$_PO ST['EndDate'];
      >
      >
      <?php
      $sql = "SELECT DISTINCT(LEFT(d tDateTime,9)) As NewD FROM dbo_J1708Data
      WHERE (dtDateTime Between ' $StartD ' AND ' $EndD ' )";
      >
      $result= mysql_query($sq l) or die();
      ?>
      >
      >
      <form id="form1" name="form1" method="post" action="result. php">
      >
      <table>
      <tr>
      <td width="83" height="27">Tim e Series:</td>
      <td width="105">
      <select name="TS" id="TS">
      <?php
      while( $row = mysql_fetch_arr ay($result) )
      {
      echo '<option value="'.$row['NewD'].'">'.$row['NewD'].'</option>';
      }
      ?>
      </select></td </tr</table>
      >
      Gordon has told you one problem, but there are others.

      Even if you were right about the date format,

      $StartD=(int)$_ POST['StartDate']

      would deliver the first bit of the date - in your format, the month
      only. (see
      http://www.php.net/manual/en/languag...ng.conversion).

      You can't just expect a date to convert to a usable integer like that.

      Secondly, you've already pointed out the weakness of using LEFT for what
      you want to do. Use one of the DATE functions: see


      Thirdly, your question about forms: no, you can give only one URL far
      'action'. If you want to be able to go to different pages (presumably
      depending on values in the form) you need to write a CGI script that
      takes the values from the form, decides which page to go to, and then
      issues an appropriate
      header()

      You must make sure you do not output anything (not even spaces) before
      the header.

      Colin

      Comment

      Working...