2017-10-21 13 views
1

echo currentecho next을 사용하여 SQL 쿼리에서 채워진 세션 변수에 결과를 출력하려고합니다. 그러나 화면에 텍스트가 표시되지 않습니다.세션 PHP 배열의 다음 레코드 표시

배열 번째 항목 반향

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

시도 (전류) 배열의 첫 번째 항목 반향 배열 $SQL = "Select * from Property_Features WHERE pf_pr_ID = 3"; $result = $conn->query($SQL); $_SESSION[arrProperty_Features] = $result->fetch_assoc();

시도가 데이터를 얻기 위해 사용 넣고 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이 될 때까지 iterating 유지 – Tarun

+0

감사합니다 Tarun - 나는 이것을 시도했지만 그것은 영원한 루프에 갇혀있는 것 같습니다 while ($ result = $ conn-> query ($ SQL)) { \t $ _SESSION [arrProperty_Features] = $ result-> fetch_assoc(); } –

답변

0

다음 코드를 시도하면 원하는 결과를 얻으실 수 있습니다. 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>