When the user initially goes to the page I want it to display the most recent days worth of data. Generally for any given days worth of data there would be 2-3 different expiration dates and I would want each set of expiration dates in there own table. Example would be 10 stocks with May 21 expiration and 10 stocks with June 18 expiration. My hiccup is if they come in on a day where there is no data I would need to grab the most recent. So if they cam in on Saturday I would need to grab Fridays if it was in there or the most recent if that was not in there for any reason.
My second part is I want to give the user the option to go back/forward days for historical purposes. So when they initially enter there are no days forward so I would only need to grab the postdate of the entry prior to that days entry. Once they clicked on that to go back a day now I need to grab the prior days postdate and next days postdate so they could go back one day or forward one day.
Right now I got it to the point where I grab all of the postdates in the DB and I can click on any given day to see the data. Then I grab that days data and display it in one table which really I want broken into multiple tables depending on the expiration date.
Code: Select all
$sql = "SELECT distinct postdate FROM `trades` order by postdate desc";
$result = mysql_query($sql, $link);
if (!$result) {
echo "DB Error, could not query the database\n";
echo 'MySQL Error: ' . mysql_error();
exit;
}
print "<table><tr><td>What day would you like to view?</td></tr>";
while ($row = mysql_fetch_row($result))
{
foreach ($row as $field)
{
print "<tr><td nowrap=\"nowrap\" align=\"center\" bgcolor=\"$row_color\"><a href=\"$_SERVER[PHP_SELF]?date=$field\">$field</a></font></td></tr>";
}
$row_count++;
}
print "</table>";
if (isset($_REQUEST['date']))
{
$date = $_REQUEST['date'];
} else {
$date = date("Y-m-d");
}
$sql = "SELECT premium, downside, symbol, expire, close, strike, ivalue, evalue, bid, ask, postdate FROM `trades` WHERE `postdate` = '". $date."'";
if (isset($_REQUEST['Orderby']))
{
$sql = $sql . " Order By ". $_REQUEST['Orderby'];
} else {
$sql = $sql . " Order By expire, premium desc";
}
//print $sql;
$result = mysql_query($sql, $link);
if (!$result) {
echo "DB Error, could not query the database\n";
echo 'MySQL Error: ' . mysql_error();
exit;
}
// Define colors for alternating rows
$color1 = "#fffaf0";
$color2 = "#ffffff";
$row_count = 0;
$row = mysql_fetch_assoc($result);
if (!empty($row)) {
print "<table align=\"center\" border=\"0\" cellpadding=\"2\" bgcolor=\"#4F5158\">";
print "<tr style=\"color: white;\">
<th><a href=\"/listtrades.php?date=2010-04-27&Orderby=premium\">Return</a></th>
<th><a href=\"/listtrades.php?date=2010-04-27&Orderby=downside\">Downside</a></th>
<th><a href=\"/listtrades.php?date=2010-04-27&Orderby=symbol\">Symbol</a></th>
<th><a href=\"/listtrades.php?date=2010-04-27&Orderby=expire\">Expire</a></th>
<th><a href=\"/listtrades.php?date=2010-04-27&Orderby=close\">Close</a></th>
<th><a href=\"/listtrades.php?date=2010-04-27&Orderby=strike\">Strike</a></th>
<th><a href=\"/listtrades.php?date=2010-04-27&Orderby=ivalue\">I Value</a></th>
<th><a href=\"/listtrades.php?date=2010-04-27&Orderby=evalue\">E Value</a></th>
<th><a href=\"/listtrades.php?date=2010-04-27&Orderby=bid\">Bid</a></th>
<th><a href=\"/listtrades.php?date=2010-04-27&Orderby=ask\">Ask</a></th>
<th><a href=\"/listtrades.php?date=2010-04-27&Orderby=postdate\">Posted</a></th></tr>";
while ($row = mysql_fetch_row($result))
{
$row_color = ($row_count % 2) ? $color1 : $color2;
print "<tr>";
foreach ($row as $field)
{
print "<td nowrap=\"nowrap\" align=\"center\" bgcolor=\"$row_color\"><font size=\"2\">$field</font></td>";
}
print "</tr>";
$row_count++;
}
print "</table>";