我已经在使用店铺收入的每日报告,但我需要我的报告执行以下操作:我想查看特定日期范围的收入报告,或几周或几个月......基本上,我可以选择我希望看到哪几天或哪几天,以便我可以打印我的选择。如何在mysql中使用特定日期范围的报告
这里是inc.php
<?
$dbtype = "mysql";
$dbhost = "localhost";
$dbname = "anillos";
$dbuser = "rubi";
$dbpass = "----";
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
$conn->exec("set names utf8");
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
?>
这里是我的代码:
<table class="table-bordered table-striped table-condensed">
<thead>
<tr>
<th>Fecha</th>
<th>Total Anillos Vendidos</th>
<th>Total ganado del día</th>
</tr>
</thead>
<tbody id="result_fechas">
<tr>
<?
include 'inc.php';
$sql = $conn->prepare("SELECT DATE(start) AS date, COUNT(id_anillos) AS total_anillos, SUM(ventas) AS total_diario_ganado
FROM PRODUCTOS WHERE start >= CURDATE() AND start < CURDATE() + INTERVAL 1 DAY ORDER BY start ASC");
$sql->execute();
while($row = $sql->fetch(PDO::FETCH_ASSOC)) {
?>
<td class="center"><? echo $row['date']; ?></td>
<td class="center"><? echo $row['total_anillos']; ?></td>
<td class="center"><? echo $row['total_diario_ganado']; ?></td>
</tr> <? } ?>
</tbody>
你可以帮我this..I真的没有线索...
---- UPDATE -----
@ Chris78我做了这个形式:
<form name="fechas" id="fechas" method="post" >
<fieldset>
<legend>Reporte desde : </legend>
<input type="text" value="" placeholder="YYYY-MM-DD" name="f_desde" id="datepicker"/>
<legend>Reporte hasta : </legend>
<input type="text" value="" placeholder="YYYY-MM-DD" name="f_hasta" id="datepicker2" />
<button class="btn btn-inverse" type="submit" name="enviar" >
<i class="icon icon-print icon-white"></i>
Ver Reporte </button>
</fieldset>
</form>
新选择代码:
<?
$sql = $conn->prepare("SELECT DATE(start) AS date, COUNT(id_anillos) AS total_anillos, SUM(ventas) AS total_ganado FROM PRODUCTOS WHERE start BETWEEN 'f_desde' AND 'f_hasta' ORDER BY start ASC");
$sql->execute();
while($row = $sql->fetch(PDO::FETCH_ASSOC)) {
?>
表:
<table class="table-bordered table-striped table-condensed">
<thead>
<tr>
<th>rango de fechas seleccionado</th>
<th>Total Anillos Vendidos</th>
<th>Total ganado</th>
</tr>
</thead>
<tbody id="result_fechas">
<tr>
<?
////////SELECT CODE HERE
?>
<td class="center"><? echo $row['date']; ?></td>
<td class="center"><? echo $row['total_anillos']; ?></td>
<td class="center"><? echo $row['total_ganado']; ?></td>
</tr> <? } ?>
</tbody>
,我试图表明,在Ajax调用的结果同一页
<script type="text/javascript">
$(function(){
$("#fechas").submit(function(){
$.ajax({
type:"POST",
url:".reportes.php?ts=" + new Date().getTime(),
dataType:"text",
data:$(this).serialize(),
beforeSend:function(){
$("#loading").show();
},
success:function(response){
$("#result_fechas").append(response);
$("#loading").hide();
}
})
return false;
});
});
});
</script>
reportes.php是相同的页面,其中是等待结果的表格和表格......但我不知道错误在哪里,因为不抓住ajax的数据和页面刷新时,按钮...你能帮助我吗?
您可以简单地将您的字段发布到'variable'并运行'query'。例如:'$ fromdate = $ _POST ['f_desde']; $ todate = $ _POST ['f_hasta'];''WHERE start BETWEEN'“。$ fromdate。”'AND'“。$ todate。”''希望能帮助你。 – Chris78
谢谢你们这些变数让它成功!最好的祝福! –
非常欢迎您!乐意效劳 :) – Chris78