向此查询添加where子句时遇到问题。我希望它选择列'SAT AM/SUN PM‘是'yes’,列'confirmed‘是'yes’。
如果没有'WHERE shift_times='SAT AM/SUN PM‘,它就可以工作--它不会输出任何内容:
$query = "SELECT position, COUNT(confirmed) FROM volConfirm WHERE shift_times='SAT AM/SUN PM' GROUP BY position";
$result = mysql_query($query) or die(mysql_error());
// Print out result
while($row = mysql_fetch_array($result)){
echo "There are ". $row['COUNT(confirmed)'] ." ". $row['position'] ." " . $row['shift_times'] . " volunteers.";
echo "<br />";更多信息:该表包含使用'yes‘或’0‘(表示否)确认的记录,shift_times为SAT AM/SUN PM或SAT PM/SUN AM有几个不同的位置。我试着像这样展示最终的结果:
有"30“”艺术“志愿者参加"SAT AM/SUN PM”
有"30“”艺术“志愿者参加"SAT PM/SUN AM”
理想情况下,行应该旋转,这样下面的回声就是"SAT PM/SUN AM“的反向数据--但这看起来有点棘手……
发布于 2012-05-09 13:51:58
我将您的select语句更改为select和group by shift time,这样每个轮班时间的每个位置都会选择一行。我在count()中添加了一个别名' cnt‘,并更新了php,以便在echo语句中使用cnt在while循环末尾没有右括号(可能是复制粘贴问题)
$query = "SELECT COUNT(confirmed) as cnt
, position
, shift_times
FROM volConfirm
WHERE confirmed='yes'
GROUP BY shift_times, position
order by shift_times, position";
$result = mysql_query($query) or die(mysql_error());
// Print out result
while($row = mysql_fetch_array($result))
{
echo "There are ". $row['cnt'] ." ". $row['position'] ." " . $row['shift_times'] . " volunteers.";
echo "<br />";
}https://stackoverflow.com/questions/10510072
复制相似问题