简体   繁体   中英

Data Loop gone wrong

I've got the first round of this loop displaying correctly. What I want is 5 rows of 8 columns. What I'm getting is the first group displays correctly and the second group displays as 10 columns.

Where am I going wrong?

echo '<table align="center" width="70%"><tr>'; 
$count = 0; 
$rowCount = 0;
while ( $row = mysql_fetch_array($result)) 
{ 
  $count++;    
  echo "<td><a href='" . $row['URL'] . "'><img src='" . $row['IMG'] . "' width='120' h     eight='160'/></a></td>"; 

if ($count % 8 === 0) 
{ 

    echo '</tr>';
$rowCount++;

if($rowCount % 8 === 0)
 {
    echo '</tr></table><br><br>Adds here<br><br><tablealign="center" width="70%"><tr>';
 }else{
    echo '<tr>';
 }
  } 
}     
echo ' </tr></table>'; 

You're trying to make it a little too complicated.

Separate out the functionality for the column counts versus the row counts:

<?php

echo '<table align="center" width="70%"><tr>'; 
$count = 0; 
$rowCount = 0;
while($row = mysql_fetch_array($result)) 
{ 
    $count++;
    echo "<td><a href='" . $row['URL'] . "'><img src='" . $row['IMG'] . "' width='120' h     eight='160'/></a></td>"; 
    if($count%8===0)
    {
        $rowCount++;
        echo '</tr>';

        if($rowCount%5===0)
        {
            echo '</table><br/><br/>Adds Here<br/><br/><table align="center" width="70%"><tr>';
            $rowCount = 0;
        }
    }
}
echo ' </tr></table>'; 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM