need help on query sort
Posted: Sun Sep 02, 2007 5:32 am
i have a module that sorts all reports by date but it doesn't work.. i'm guessing its my query but i'm not that good in guessing
basically all i want to do is display data depending on what the client is asking.. for example if a client would choose form the dropdown list to display reports in march all reports in march should appear but it doesnt..
here is my code for the form:
and in this form the is the query:
could it be my query is incomplete? i'am really not that good in php so please help! thank you!
here is my code for the form:
Code: Select all
<?php
if (!defined('WEB_ROOT')) {
exit;
}
$sql = "SELECT *
FROM tbl_order od, tbl_order_item o, tbl_product pd
WHERE o.pd_id = pd.pd_id and o.od_id = od.od_id AND od_status = 'Paid'";
$result = dbQuery($sql);
$totalsale = 0;
$totalqty = 0;
?>
<form action="getreports.php" method="post" name="getReports" id="getReports">
<table width="80%" cellpadding="5" cellspacing="0" border="1" sytle="font-family:arial;color:purple;font-size:12px" align="center">
<tr>
<td style="font-size:20px;color:purple;font-family:arial" colspan="7" align="center">SALES REPORT</td>
</tr>
<tr>
<td colspan="7">
Month required<br><br>
<select name="month" id="month">
<option>--selected--</option>
<option value="01">January</option>
<option value="02">Febuary</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select> <input type="button" value="sort" onclick="salesreport();">
</td>
</tr>
<tr>
<td>Order Date</td>
<td>Order ID</td>
<td>First Name</td>
<td>Last Name</td>
<td>Order Quantity</td>
<td>Price</td>
<td>Total Amount(Tax included)</td>
</tr>
<?php
while ($row = dbFetchAssoc($result)){
extract($row);
$tax = $pd_price * 0.12;
$total = $od_qty * $pd_price + $tax;
$totalsale += $total;
$totalqty += $od_qty;
?>
<tr>
<td><?php echo $od_date;?></td>
<td align="center"><?php echo $od_id;?></td>
<td><?php echo $od_payment_first_name;?></td>
<td><?php echo $od_payment_last_name;?></td>
<td align="center"><?php echo $od_qty;?></td>
<td><?php echo displayAmount($pd_price);?></td>
<td align="center"><?php echo displayAmount($total);?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="7">
</td>
</tr>
<tr>
<td colspan="7">
<?php echo "Total Items Sold:"." ".$totalqty;?>
</td>
</tr>
<tr>
<td colspan="7">
<?php echo "Total Sales:"." ".displayAmount($totalsale);?>
</td>
</tr>
</table>
</form>and in this form the is the query:
Code: Select all
<?php
require_once '../../library/config.php';
require_once '../library/functions.php';
checkUser();
$action = isset($_GET['action']) ? $_GET['action'] : '';
switch ($action) {
case 'sales' :
salesReport();
break;
default :
// if action is not defined or unknown
// move to main user page
header('Location: index.php');
}
function salesReport()
{
$month = $_POST['month'];
$sql = "SELECT *
FROM tbl_oder od, tbl_order_item o, tbl_product pd
WHERE od.od_id = o.od_id AND o.pd_id = pd.pd_id AND MONTH (od.od_date) = '$month'";
$result = dbQuery($sql);
header("Location: index.php");
}
?>