Re: php
- From: Colin Fine <news@xxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 08 Oct 2006 11:44:12 +0100
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)$_POST['EndDate'];
<?php
$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">
<table>
<tr>
<td width="83" height="27">Time Series:</td>
<td width="105">
<select name="TS" id="TS">
<?php
while( $row = mysql_fetch_array($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/language.types.string.php#language.types.string.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 http://mysql.org/doc/refman/4.1/en/date-and-time-functions.html
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
.
- References:
- php
- From: kirke
- php
- Prev by Date: Re: Problem retrieving an object from an array and calling a method on the object
- Next by Date: Re: Creating Dynamic URLs
- Previous by thread: Re: php
- Next by thread: Skip 'Insertion' Page
- Index(es):