2017-10-21 60 views
1

我试图在已使用echo currentecho next从SQL查询填充的会话变量中输出结果。但是没有文字回显到屏幕。在会话中显示下一条记录php数组

用于获取数据并投入阵列 $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>

尝试在阵列呼应第二项SQL语句(下)
<p><input class="w3-input" name="txtFeature2" type="text" id="txtFeature2" value="<?php echo next ($_SESSION[arrProperty_Features][pf_Feature]);?>"><br>

+0

“$ result-> fetch_assoc()”不会一次给你所有的结果。继续迭代它,直到它给你null – Tarun

+0

谢谢塔伦 - 我试过这个,但它似乎被困在一个永恒的循环中 while($ result = $ conn-> query($ SQL)){ \t $ _SESSION [arrProperty_Features] = $ result-> fetch_assoc(); } –

回答

0

尝试下面的代码,我想你会得到想要的结果。 PHP当前或下一个函数工作在单个数组而不是多维数组。通过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>