2017-10-21 75 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>