the other one is week.php which is below.When I click date in calender.php it passes the date to week.php
my table is in mysql ,name testdb. it contain three columns( date item and price.)
After getting date
date item price
eg.
2009-01-20 xerox paper 90
2009-01-20 transparency cover 12
2009-01-13 xerox paper 100
2009-01-13 transparency cover 14
end result should be
xerox paper 90-100 -10 and % of that
ransparency cover 121-4 -2 %
I am not a professional programmer, I learn programming using internet, reading books and asking experts.
MY CODE LOOK LIKE THIS
Code: Select all
< php
include "dbcon1.php";
$date1=$_GET['date']; // this is initial date 2009-01-20
echo"$date1". "<br />";
$difference = strtotime ( '-1 week' , strtotime ( $date1 ) ) ; // getting week ago
$date2=date ( 'Y-m-d' , $difference ) . "<br />\n" ; //this is week ago in the required format 2009-01-13
$sql = "SELECT item, price FROM table1 WHERE (((table1.date)='$date1')) "; //getting price on 2009-01-20
$sql1 = "SELECT price FROM table1"."WHERE (((table1.date)='$date2'))"; //getting price on 2009-01-13
$result = mysql_query($sql)
or die(mysql_error());
$result2 = mysql_query($sql1)
or die(mysql_error());
$header=<<<EOD
<h2><center>price variation - <font color="red" size="6"> </center></h2>
<table width="70%" border="1" cellpadding="2"
cellspacing="2" align="center">
<tr>
<th>DATE</th>
<th>ITEM</th>
<th>PRICE</th>
<th>DIFFERENCE</th>
<th>PERCENT</th>
</tr>
EOD;
$details = '';
while ($row = mysql_fetch_array($result2))
{
$price2 = $row['price'];
} //
while ($row = mysql_fetch_array($result))
{
// $date = $row['date'];
$item = $row['item'];
$price = $row['price'];
$price1 = $price2; // This Line is out of reach for looping through. of $result2.
$gain =($price-$price1); // this is what i exaclty required.
$percentage=(($gain*100)/$price1);
$details .=<<<EOD
<tr>
<td>$date</td>
<td><font color="red" size="4"> $price</td>
<td> $price11</td>
<td><font color="red" size="4"> $gain</td>
<td><font color="blue" size="4"> $percentage</td>
</tr>
EOD;
}
$footer ="</table>";
$output =<<<ALL
$header
$details
$footer
ALL;
echo $output;
?>