2017-10-21 52 views
1

echo currentecho nextを使用してSQLクエリから取り込まれたセッション変数に結果を出力しようとしています。しかし、テキストは画面にエコーされません。データを取得し、配列に配列の最初の項目をエコーする $SQL = "Select * from Property_Features WHERE pf_pr_ID = 3"; $result = $conn->query($SQL); $_SESSION[arrProperty_Features] = $result->fetch_assoc();セッションPHP配列の次のレコードを表示

試み(現在)

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

アレイの2番目の項目をエコーし​​よう(次)を挿入するために使用

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

ありがとうTarun - これを試しましたが、永遠のループで固まっているようです。 [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>