Do you have a question? Post it now! No Registration Necessary. Now with pictures!
October 8, 2006, 3:10 am
rate this thread
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 '
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
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.
$sql = "SELECT DISTINCT(LEFT(dtDateTime,9)) As NewD FROM dbo_J1708Data
WHERE (dtDateTime Between ' $StartD ' AND ' $EndD ' )";
$result= mysql_query($sql) or die();
<form id="form1" name="form1" method="post" action="result.php">
<td width="83" height="27">Time Series:</td>
<select name="TS" id="TS">
while( $row = mysql_fetch_array($result) )
echo '<option value="'.$row['NewD'].'">'.$row['NewD'].'</option>';
</select></td> </tr> </table>
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,
Gordon has told you one problem, but there are others.
Even if you were right about the date format,
would deliver the first bit of the date - in your format, the month
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
You must make sure you do not output anything (not even spaces) before
- » Looking for very simple and dynamic photo gallery based on directories...
- — Previous thread in » PHP Scripting Forum