Forum Moderators: coopster
<?php
if (isset($_REQUEST['Submit']))
{
$StartDate = $_REQUEST["StartDate"];
$EndDate = $_REQUEST["EndDate"];
}
$result=mysql_query("SELECT * FROM Counterparty2008 WHERE TradeDate =>' $_REQUEST'[StartDate] and TradeDate <' $_REQUEST'EndDate'", $link);
print "<table border=\1\><tr><th>Broker</th>";
print "<th>AccountN</th> <th>TicketN</th> <th>TradeDate</th> <th>ValueDate</th> <th>CCYPair</th> <th>BS</th> <th>Amount</th> <th>StrikePrice</th> <th>ID</th> <th>Comentary</th>";
while ($row= mysql_fetch_array($result))
{
print "<tr>";
foreach($row as $field)
{
print "<td>$field</td>";
}
print "</tr>";
}
print"</table>";
mysql_close($link);
?>
So poin is that I wan to retrive data with form and in form I have dates
<html>
<head>
<title>Dealers Traded Lots data</title>
</head>
<body>
<form action="myconection2.php" method= "post">
<table>
<tr>
<td>Start Date (yyyy-mm-dd): </td>
<td><input type="text" name ="StartDate"></td>
</tr>
<tr>
<td>End Date (yyyy-mm-dd):</td>
<td><input type="text" name ="EndDate"></td>
</tr>
<tr><td colspan=2 align=left>
<tr><td>
<input type="Submit" value ="Submit">
</table>
</form>
</body>
</html>
please help me if you can.
thank you
[edited by: jatar_k at 2:40 pm (utc) on Nov. 7, 2008]
[edit reason] fixed sidescroll [/edit]
I think your question is basically how to form the proper mysql-query from php, because it looks faulty to me.
I'd suggest like this:
$result = mysql_query("SELECT * FROM Counterparty2008 WHERE TradeDate =>'".$_REQUEST['StartDate']."' and TradeDate <'".$_REQUEST['EndDate']."';", $link);
note the dots (.) which joins strings. and note the different quotation marks: start with double quotes (for php), start the single quotes (for mysql), end double quotes (php), join in php-variable, restart double quotes (php), end single quotes (mysql), continue sql statement, ...
this is the most correct way to do it: keep your php-variables out of the strings, by closing the string and joining the variable (and joining more strings in this case).
there's more to quotes, but I'll leave it for now. ;-)
this is the most correct way to do it: keep your php-variables out of the strings, by closing the string and joining the variable (and joining more strings in this case).
PHP variables will work within Double quotes, its just that when you want arrays to work within double quotes you need to do some little extra, but if u want to avoid that then simply copy the array value on that index to a variable and use that variable name. Like you are storing $_REQUEST["StartDate"] into $StartDate, so why not use $StartDate and simplify our query.
<?php
if (isset($_REQUEST['Submit']))
{
$StartDate = $_REQUEST["StartDate"];
$EndDate = $_REQUEST["EndDate"];
}
$result=mysql_query("SELECT * FROM Counterparty2008 WHERE TradeDate =>'$StartDate' and TradeDate < '$EndDate'", $link);
print "<table border=\1\><tr><th>Broker</th>";
print "<th>AccountN</th> <th>TicketN</th> <th>TradeDate</th> <th>ValueDate</th> <th>CCYPair</th> <th>BS</th> <th>Amount</th> <th>StrikePrice</th> <th>ID</th> <th>Comentary</th>";
while ($row= mysql_fetch_array($result))
{
print "<tr>";
foreach($row as $field)
{
print "<td>$field</td>";
}
print "</tr>";
}
print"</table>";
mysql_close($link);
?>
So poin is that I wan to retrive data with form and in form I have dates
<html>
<head>
<title>Dealers Traded Lots data</title>
</head>
<body>
<form action="myconection2.php" method= "post">
<table>
<tr>
<td>Start Date (yyyy-mm-dd): </td>
<td><input type="text" name ="StartDate"></td>
</tr>
<tr>
<td>End Date (yyyy-mm-dd):</td>
<td><input type="text" name ="EndDate"></td>
</tr>
<tr><td colspan=2 align=left>
<tr><td>
<input type="Submit" value ="Submit">
</table>
</form>
</body>
</html>
[edited by: Anyango at 5:48 am (utc) on Nov. 8, 2008]