Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我如何根据用户级别,仅在过去的一周内,从一列中合计出“是”?使用PHP和SQL_Php_Mysql_Sql_Sum - Fatal编程技术网

我如何根据用户级别,仅在过去的一周内,从一列中合计出“是”?使用PHP和SQL

我如何根据用户级别,仅在过去的一周内,从一列中合计出“是”?使用PHP和SQL,php,mysql,sql,sum,Php,Mysql,Sql,Sum,我希望有一个简单的问题,我只是无法得到任何我试图工作 基本上,我正在寻找一种方法,简单地计算从周一开始的过去一周内,用户级别=一个数字,用户名=一个用户名的每一列中的“是”。也可用于合计amounttot列中的金额 我的SQL数据库设置如下: 数据库名称:1\u 1表格:表格2 数据库中的数据样本 我如何让它列出每个团队的所有数据,我只需要在下面打印出一个完全不同的表格,我可以放在下面。我如何让它只显示从周一开始的最后几周的数据: <?php $con = mysql_connect("l

我希望有一个简单的问题,我只是无法得到任何我试图工作

基本上,我正在寻找一种方法,简单地计算从周一开始的过去一周内,用户级别=一个数字,用户名=一个用户名的每一列中的“是”。也可用于合计amounttot列中的金额

我的SQL数据库设置如下:

数据库名称:1\u 1表格:表格2

数据库中的数据样本

我如何让它列出每个团队的所有数据,我只需要在下面打印出一个完全不同的表格,我可以放在下面。我如何让它只显示从周一开始的最后几周的数据:

<?php
$con = mysql_connect("localhost","1_1","XXXXXXXXXXXXXXXX");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("1_1", $con);

$result = mysql_query("SELECT * FROM form_2 WHERE userlevel = '5' ORDER BY timestamp DESC");

echo "<table border='1'>
<tr>
<th><font size='1'>Name</th>
<th><font size='1'>Latitude</th>
<th><font size='1'>Longatude</th>
<th><font size='1'>Inspect</th>
<th><font size='1'>Sig</th>
<th><font size='1'>Phone #</th>
<th><font size='1'>Insur</th>
<th><font size='1'>Claim</th>
<th><font size='1'>Appr</th>
<th><font size='1'>AdjusApp</th>
<th><font size='1'>Check</th>
<th><font size='1'>Amount</th>
<th><font size='1'>Time</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td><font size='1'>" . $row['username'] . "</font></td>";
  echo "<td><font size='1'>" . $row['lat'] . "</font></td>";
  echo "<td><font size='1'>" . $row['longa'] . "</font></td>";
  echo "<td><font size='1'>" . $row['inspect'] . "</font></td>";
  echo "<td><font size='1'>" . $row['signatu'] . "</font></td>";
  echo "<td><font size='1'>" . $row['gotphone'] . "</font></td>";
  echo "<td><font size='1'>" . $row['hain'] . "</font></td>";
  echo "<td><font size='1'>" . $row['claimnum'] . "</font></td>";
  echo "<td><font size='1'>" . $row['approved'] . "</font></td>";
  echo "<td><font size='1'>" . $row['adjustapprov'] . "</font></td>";
  echo "<td><font size='1'>" . $row['checkcollec'] . "</font></td>";
  echo "<td><font size='1'>" . $row['amounttot'] . "</font></td>";
  echo "<td><font size='1'>" . $row['timestamp'] . "</font></td>";

  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?> 
任何帮助都将不胜感激。多谢各位

这里有一个建议:

SELECT userlevel, COUNT(*)
FROM form_2
WHERE timestamp BETWEEN x AND y
AND signatu = 'yes'
GROUP BY userlevel
“x”和“y”必须是限定查询的时间戳——它们可以由PHP提供,也可以直接在MySQL中查找

编辑:修复了查询,感谢@knittl

SELECT userlevel, COUNT(*)
FROM form_2
WHERE timestamp BETWEEN x AND y
AND signatu = 'yes'
GROUP BY userlevel