从许多变量中获得一个会话

时间:2017-01-11 09:27:14

标签: php mysql variables mysqli

<?php
    $kid = $_SESSION["kid"];
    $sql = "SELECT Gericht_ID FROM `warenkorb` WHERE Kunde_ID = '$kid'";
    $result = mysqli_query($con,$sql);
    if(mysqli_num_rows($result) > 0) {
        while ($row = mysqli_fetch_array($result)) {
            $_SESSION['row_gid'] = $row["Gericht_ID"];
            print $_SESSION['row_gid']; // he return me here 2 9 10 11     
        }
    }
    print $_SESSION['row_gid']; // but here just only 11
?>

我的问题是如何将SESSION中的值保存为所有数字2 9 10 11不仅仅是11?

2 个答案:

答案 0 :(得分:1)

您可以使用$_SESSION['row_gid'][],然后在外部循环打印$_SESSION['row_gid']

答案 1 :(得分:0)

改变
$sql = "SELECT Gericht_ID FROM `warenkorb` WHERE Kunde_ID = '$kid'";

$sql = "SELECT group_concat(Gericht_ID separator ',') as Gericht_ID FROM `warenkorb` WHERE Kunde_ID = '$kid'";