2014-03-26 2 views
0

완벽하게 작동하는 프로젝트에서이 코드를 사용했지만, 첫 번째 레코드가 항상 표시되지 않습니다. 예 : SQL 쿼리는 15 개의 결과를 나열하지만 출력은 첫 번째 레코드가 누락 된 14 개만 표시합니다. 어떤 아이디어?루핑 레코드 세트 PHP

<?php 
$result = mysql_query($sql); 

//first put all the results into an array so we can look backward and see previous items 
$resultSet = array(); 
while($record = mysql_fetch_array($rs2Dfiles)) { 
$resultSet[] = $record; 
} 

for ($i = 0 ; $i < count($resultSet) ; $i++) { 
if ($i == 0) { 
//for the first item, show the category name 
echo '<div class="Box"><div class="BoxHeader gfgreen"><h3>'.$resultSet[$i]['ftCatName'].'</h3> </div>'; 
} else if ($resultSet[$i]['ftCatName'] != $resultSet[$i-1]['ftCatName']) { 
//every time we encounter a new category, display a new line and show the category name 
echo '</div><div class="Box"><div class="BoxHeader gfgreen"><h3>'.$resultSet[$i] ['ftCatName'].'</h3></div>'; 
} 

echo '<p class="Document"><a title="View file details" href="download.php?id='.$resultSet[$i] ['DownloadID'].'">'.$resultSet[$i]['DownloadName'].'</a> ('.formatSize( filesize('DOCS/'.$resultSet[$i]['DownloadFilename'].'')).')</p>'; 
} 
echo '</div>'; 
?> 
+0

전체 코드를 검색어로 ..... 제공하십시오! –

+1

참고 :'mysql_ *'은 더 이상 사용되지 않습니다. mysqli_ * 또는'PDO'를 사용해야한다. –

답변

1

foreach를 사용하면 더 쉽게 작업 할 수 있습니까?

$last = null; 

foreach($resultSet as $resultRow) 
{ 
    if ($resultRow != $last) 
    { 
     echo 'your html content goes here'; 
     echo $resultRow['propertyName']; 
    } 

    $last = $resultRow 
}