0

我的问题是为什么它不显示 $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>";
4

2 回答 2

1

当你

select ... SUM(menr.aantalkeermenu)

结果列将不会被调用aantalkeermenu。您需要明确命名该列,如下所示

select ... SUM(menr.aantalkeermenu) as aantalkeermenu

然后它将出现在结果行中的该名称下。

于 2013-01-09T10:41:53.637 回答
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";
于 2013-01-09T10:42:17.467 回答