我已经在使用商店收入的每日报告,但我需要我的报告执行以下操作:我想查看特定日期范围、周或月的收入报告......本质上我可以选择我想查看的日期或日期范围,以便打印我的选择。
这里是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>
你能帮我解决这个问题吗...我真的不知道...
----更新-----
@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 数据,并且当我刷新页面时单击按钮...您能帮我解决这个问题吗?
最佳答案
如果您想要运行带有日期范围的查询
,您可以使用BETWEEN
语句。
$sql = $conn->prepare("SELECT DATE(start) AS date, COUNT(id_anillos) AS total_anillos, SUM(ventas) AS total_diario_ganado
FROM PRODUCTOS WHERE start BETWEEN 'Older Date Here' AND 'Newer Date Here' ORDER BY start ASC");
关于php - 如何在mysql中制作具有特定日期范围的报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17606704/