2011-10-26 2 views
0

사진 갤러리를 테이블에 표시해야하는데 각 줄마다 5 장의 그림을 원하지만 각 다섯 번째 그림 뒤에 </tr><tr>을 삽입하는 방법을 찾을 수 없습니다. 그런 다음 for 루프로 같은 것을 배치html 테이블에 php 사진 갤러리 표시

for($i = 0; $rows= mysql_fetch_assoc($result); ++$i) { 

와 라인

while($rows= mysql_fetch_assoc($result)){ 

를 교체

<?php 

// table name 
$tbl_name=gallery1; 
$sql="SELECT * FROM $tbl_name"; 
$result=mysql_query($sql); 

while($rows= mysql_fetch_assoc($result)){ 

$id   = $rows['id']; 
$path  = $rows['path']; 
$image_name = $rows['image_name']; 
$title  = $rows['title']; 
?> 


<img src="<?php echo $path."/".$image_name;?>" height="120"/>Name:<?php echo $title;?> 
<?php 
echo "<form action='pictry.php' enctype='multipart/form-data' method='post'> 
<input name='file[]' type='hidden' value='".$image_name."' /> 
<input name='id' type='hidden' id='id' value='".$id."'/> 
<input type='submit' name='button' id='button' value='Delete Picture' /></form>"; 

} 
?> 

답변

1

: 다음은 내 코드입니다.

if($i % 5 == 0) { /* insert stuff */ } 
+0

대단히 감사합니다. – Tamara

0

테스트되지 않은 코드

<?php 
    $perrow = 5; 
    $i = 0; 
    echo '<table>'; 
    echo '<tr>'; 
    while($rows = mysql_fetch_assoc($result)) { 
    echo '<td><img src=[grapresultfromrows] /></td>'; 
    ++$i; 
    if($i == $perrow) { 
     $i = 0; 
     echo '</tr>'; 
     echo '<tr>'; 
    } 
    } 
    // If not a multiple of $perrow you need to add extra cells 
    for($i; $i < $perrow; ++$i) { 
    echo '<td></td>'; 
    } 
    echo '</tr>'; 
    echo '</table>'; 
?>