我的问题是为什么它没有显示$ aantalkeermenu。但它显示了查询中的其他变量,任何人都可以帮助我吗?
这是我的疑问:
$sql = "SELECT res.reserveringsnr, res.datum, menr.reserveringsnr, menr.menunr, SUM(menr.aantalkeermenu), men.menunr, men.menunaam, men.voorgerecht, men.hoofdgerecht, men.nagerecht FROM reserveringen AS res
INNER JOIN menus_regel as menr
ON res.reserveringsnr = menr.reserveringsnr
INNER JOIN menus AS men
ON menr.menunr = men.menunr
WHERE res.datum = '".$invoerdatum."'
GROUP BY menr.menunr
";
以下是在我的网页上显示的内容:
$result = mysql_query($sql);
echo "<table>";
echo "<th>Aantal</th> <th> Menunaam </th><th> Voorgerecht </th> <th> Hoofdgerecht </th> <th> Nagerecht </th>";
while($row = mysql_fetch_assoc($result)) {
$datum = $row['datum'];
$aantalkeermenu = $row['aantalkeermenu'];
$menunr = $row['menunr'];
$menunaam = $row['menunaam'];
$voorgerecht = $row['voorgerecht'];
$hoofdgerecht = $row['hoofdgerecht'];
$nagerecht = $row['nagerecht'];
$aantalkeermenu = $row['aantalkeermenu'];
// open tr
echo "<tr id='$menunr' class='edit_tr'>";
echo "<td><span>$menunr</span></td>";
echo "<td><span>$aantalkeermenu</span></td>";
echo "<td><span>$menunaam</span></td>";
echo "<td><span>$voorgerecht</span></td>";
echo "<td><span>$hoofdgerecht</span></td>";
echo "<td><span>$nagerecht</span></td>";
echo "</tr>";
// close tr
}
echo "</table>";
答案 0 :(得分:1)
当你
select ... SUM(menr.aantalkeermenu)
结果列不会被称为aantalkeermenu
。您需要明确地命名列,如此
select ... SUM(menr.aantalkeermenu) as aantalkeermenu
然后它将出现在结果行中的该名称下。
答案 1 :(得分:1)
你需要别名SUM(menr.aantalkeermenu)
别名,我认为它已归还为SUM(menr.aantalkeermenu)
以下SQL应该有所帮助。
$sql = "
SELECT res.reserveringsnr, res.datum, menr.reserveringsnr, menr.menunr,
SUM(menr.aantalkeermenu) AS aantalkeermenu, men.menunr, men.menunaam, men.voorgerecht,
men.hoofdgerecht, men.nagerecht
FROM reserveringen AS res
INNER JOIN menus_regel as menr
ON res.reserveringsnr = menr.reserveringsnr
INNER JOIN menus AS men
ON menr.menunr = men.menunr
WHERE res.datum = '".$invoerdatum."'
GROUP BY menr.menunr";