$sql="select * from shop right join ( shop_comm right join (shop_member right join (shop_sale right join shop_sorder on sale_id=sorder_sale and sale_comm=sorder_scomm) on shop_sale.sale_member=shop_member.member_id) on comm_code=sale_comm) on product_comm=sorder_pcomm and sorder_product=product_id where sorder_date between $start_day and $end_day ";
if(!empty($comm_code))
{
$sql.=" and sorder_scomm='".$comm_code."'";
}
if(!empty($member_id))
{
$sql.=" and sale_member='".$member_id."'";
}
$sql.=" order by sale_date desc" ;
$result=mysql_query($sql) or die(mysql_error().$sql);
$num_rows=mysql_num_rows($result);