【发布时间】:2018-04-02 07:32:25
【问题描述】:
我正在尝试在会话变量中输出结果,该会话变量已使用 echo current 和 echo 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>
【问题讨论】:
-
"$result->fetch_assoc()" 不会一下子给你所有的结果。继续迭代它,直到它给你 null
-
谢谢 Tarun - 我已经尝试过了,但它似乎陷入了一个永恒的循环 while($result = $conn->query($SQL)){ $_SESSION[arrProperty_Features] = $result ->fetch_assoc(); }
标签: php mysql arrays session next