posibillity to select just a month or a year...

helo guys! sir Q1712 gave me this code…it works if i choose both year and month… but if i choose only a year or a month it displays no results… i tried to change it a bit but to no success, so i have displayed the exact code sir Q1712 gave me… pls help!

[php]
$totalsale = 0;
$totalqty = 0;
$sql = “SELECT * FROM tbl_order od, tbl_order_item o, tbl_product pd WHERE od.od_id = o.od_id and o.pd_id = pd.pd_id AND od.od_status = ‘Paid’”;

if(isset($_POST[‘month’]) && !empty($_POST[‘month’]))
$sql.=" AND MONTH(od_date) = ‘".intval($_POST[‘month’])."’";
if(isset($_POST[‘year’]) && !empty($_POST[‘year’]))
$sql.=" AND YEAR(od_date) = ‘".intval($_POST[‘year’])."’";

$result = dbQuery($sql);
[/php]

do u use a select?

whats the value of the firtst option? should be something like:

Select a month

here is the form sir… sorry for the late reply…

[php]

<?php $totalsale = 0; $totalqty = 0; $sql = "SELECT od.*,pd.*,o.* FROM tbl_order od, tbl_order_item o, tbl_product pd WHERE od.od_id = o.od_id and o.pd_id = pd.pd_id AND od.od_status = 'Paid'"; if(isset($_POST['year']) && !empty($_POST['year'])){ $year = $_POST['year']; $sql = "SELECT od.*,pd.*,o.* FROM tbl_order od, tbl_order_item o, tbl_product pd WHERE od.od_id = o.od_id and o.pd_id = pd.pd_id AND od.od_status = 'Paid' AND YEAR(od_date) ='$year'"; } else if(isset($_POST['month']) && !empty($_POST['month'])){ $month = $_POST['month']; $sql = "SELECT od.*,pd.*,o.* FROM tbl_order od, tbl_order_item o, tbl_product pd WHERE od.od_id = o.od_id and o.pd_id = pd.pd_id AND od.od_status = 'Paid' AND MONTH(od_date) ='$month'"; } $result = dbQuery($sql); ?> <?php while ($row = dbFetchAssoc($result)){ extract($row);
$tax = $pd_price * $od_tax;
$total = $od_qty * $pd_price + $od_shipping_cost + $tax;
$totalsale += $total;
$totalqty += $od_qty;

?>

<?php } ?>
SALES REPORT
Month and Year required

--selected-- January Febuary March April May June July August September October November December     --selected-- 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018
Order Date Order ID First Name Last Name Order Quantity Price Total Amount(Tax included)
<?php echo $od_date;?> <?php echo $od_id;?> <?php echo $od_payment_first_name;?> <?php echo $od_payment_last_name;?> <?php echo $od_qty;?> <?php echo displayAmount($pd_price);?> <?php echo displayAmount($total);?>
 
<?php echo "Total Items Sold:"." ".$totalqty;?>
<?php echo "Total Sales:"." ".displayAmount($totalsale);?>
[/php]

thats not the code shown in ur first post.

the code of the firs post should work fine.

the problems are:

  1. because of the “else if” month is never checked when year is set.
  2. this is overwriting the query. there will be never a combined query using month and date.
Sponsor our Newsletter | Privacy Policy | Terms of Service