显示会话 php 数组中的下一条记录

Display the next record in a session php array

我正在尝试在会话变量中输出结果,该变量是使用 echo currentecho next 从 SQL 查询填充的。但是没有文本回显到屏幕。

SQL 用于获取数据并放入数组的语句 $SQL = "Select * from Property_Features WHERE pf_pr_ID = 3"; $result = $conn->query($SQL); $_SESSION[arrProperty_Features] = $result->fetch_assoc();

尝试回显数组中的第一项(当前)

<p><input class="w3-input" name="txtFeature1" type="text" id="txtFeature1" value="<?php echo current ($_SESSION[arrProperty_Features][pf_Feature]);?>"><br>

尝试回显数组中的第二项(下一个)
<p><input class="w3-input" name="txtFeature2" type="text" id="txtFeature2" value="<?php echo next ($_SESSION[arrProperty_Features][pf_Feature]);?>"><br>

试试下面的代码,我想你会得到想要的结果。 php 当前或下一个函数在单个数组而不是多维 array.through fetch_assoc() 上工作,你将得到多维数组。

<?php
    while($row = $result->fetch_assoc()) {
        $_SESSION['arrProperty_Features'][] = $row;
    }

    ?>
    <!--Attempt to echo first item in the array-->
    <p><input class="w3-input" name="txtFeature1" type="text" id="txtFeature1" value="<?php echo $_SESSION['arrProperty_Features'][0]['pf_Feature'];?>"><br>

    <!--Attempt to echo second item in the array !-->
    <p><input class="w3-input" name="txtFeature1" type="text" id="txtFeature2" value="<?php echo $_SESSION['arrProperty_Features'][1]['pf_Feature'];?>"><br>