我想实现 从数据库调出图片 在前台实现 一行显示四张图片 然后自动换行其他的接着显示!但是我写的代码只能实现一行显示所有图片 就不會自动换行了! 请各位朋友帮忙看看 代码哪里有错误!谢谢!!<?php 
header("Content-Type: text/html; charset=utf-8");
require_once("connMysql.php");
$pageRow_records = 8;
$num_pages = 1;
if (isset($_GET['page'])) {
  $num_pages = $_GET['page'];
}
$startRow_records = ($num_pages -1) * $pageRow_records;
$query_RecAlbum = "SELECT `album`.`album_id` , `album`.`album_date` , `album`.`album_location` , `album`.`album_title` , `album`.`album_desc` , `albumphoto`.`ap_picurl`, count( `albumphoto`.`ap_id` ) AS `albumNum` FROM `album` LEFT JOIN `albumphoto` ON `album`.`album_id` = `albumphoto`.`album_id` GROUP BY `album`.`album_id` , `album`.`album_date` , `album`.`album_location` , `album`.`album_title` , `album`.`album_desc` ORDER BY `album_date` DESC";
$query_limit_RecAlbum = $query_RecAlbum." LIMIT ".$startRow_records.", ".$pageRow_records;
$RecAlbum = mysql_query($query_limit_RecAlbum);
$all_RecAlbum = mysql_query($query_RecAlbum);
$total_records = mysql_num_rows($all_RecAlbum);
$total_pages = ceil($total_records/$pageRow_records);?><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>網路相簿</title>
</head><body><table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr><td><?php while($row_RecAlbum=mysql_fetch_assoc($RecAlbum)){ ?><table width=90% align="left"  border="0" cellpadding="0" cellspacing="0"><tr>
<td><img src="images/frame1.png" width="196" height="35" /></td></tr>
<tr><td><img src="images/frame3.png" width="39.5" height="108" /><a href="albumshow.php?id=<?php echo $row_RecAlbum["album_id"];?>"><?php if($row_RecAlbum["albumNum"]==0){?><img src="images/nopic.png" alt="暫無圖片" width="117" height="108" border="0" /><?php }else{?><img src="photos/<?php echo $row_RecAlbum["ap_picurl"];?>" alt="<?php echo $row_RecAlbum["album_title"];?>" width="117" height="108" border="0" /><?php }?></a><img src="images/frame4.png" width="39.5" height="108" /></div></td></tr>
<tr><td><img src="images/frame2.png" width="195.9" height="28.5" />
<?php if($startRow_records>=4) { echo "<br>";?>
<?php }?></td></tr>
</table>
<?php }?></td>
 </tr>
</table>
</body>
</html>

解决方案 »

  1.   

    <?php if($startRow_records>=4) { echo "<br>";?>
    $startRow_records = ($num_pages -1) * $pageRow_records;
    $pageRow_records = 8;
    $num_pages = 1;
    能看出來了嗎。
      

  2.   

    不知道有沒有放錯地方,好像行不通...<?php 
    header("Content-Type: text/html; charset=utf-8");
    require_once("connMysql.php");
    $pageRow_records = 8;
    $num_pages = 1;
    if (isset($_GET['page'])) {
      $num_pages = $_GET['page'];
    }$startRow_records = ($num_pages -1) * $pageRow_records;$query_RecAlbum = "SELECT `album`.`album_id` , `album`.`album_date` , `album`.`album_location` , `album`.`album_title` , `album`.`album_desc` , `albumphoto`.`ap_picurl`, count( `albumphoto`.`ap_id` ) AS `albumNum` FROM `album` LEFT JOIN `albumphoto` ON `album`.`album_id` = `albumphoto`.`album_id` GROUP BY `album`.`album_id` , `album`.`album_date` , `album`.`album_location` , `album`.`album_title` , `album`.`album_desc` ORDER BY `album_date` DESC";
    $query_limit_RecAlbum = $query_RecAlbum." LIMIT ".$startRow_records.", ".$pageRow_records;
    $RecAlbum = mysql_query($query_limit_RecAlbum);
    $all_RecAlbum = mysql_query($query_RecAlbum);
    $total_records = mysql_num_rows($all_RecAlbum);
    $total_pages = ceil($total_records/$pageRow_records);
    ?>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>私之網路相簿</title>
    </head><body><table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr><td><?php while($row_RecAlbum=mysql_fetch_assoc($RecAlbum)){ ?>
    <table width=90% align="left"  border="0" cellpadding="0" cellspacing="0"><tr><?php if($startRow_records>=4) { echo "<br>";?>
    <td><img src="images/frame1.png" width="196" height="35" /></td></tr>
    <tr><td><img src="images/frame3.png" width="39.5" height="108" /><a href="albumshow.php?id=<?php echo $row_RecAlbum["album_id"];?>"><?php if($row_RecAlbum["albumNum"]==0){?><img src="images/nopic.png" alt="暫無圖片" width="117" height="108" border="0" /><?php }else{?><img src="photos/<?php echo $row_RecAlbum["ap_picurl"];?>" alt="<?php echo $row_RecAlbum["album_title"];?>" width="117" height="108" border="0" /><?php }?></a><img src="images/frame4.png" width="39.5" height="108" /></div></td></tr>
    <tr><td><img src="images/frame2.png" width="195.9" height="28.5" /></td><?php }?>
    </tr>
    </table>
    <?php }?></td>
     </tr>
    </table>
    </body>
    </html>
      

  3.   

    <?php if($startRow_records>=4) { echo "<br>";?>
    <?php }?></td></tr>
    </table>
    <?php }?>改为<?php }?></td></tr>
    </table>
    <?php if($startRow_records>=4) { echo "<br>";?>
    <?php }?>其实采用 div+dl+dd + css 就没有这个麻烦了。
    这是网上的代码:
    CSS代码
    <style>
    *{ margin:0; padding:0;}
    #box{ width:300px; margin:10px; padding:10px; float:left; border:1px solid #CCC;
    background:#FFFFCC; font-size:12px; line-height:1.9;}
    dl{ background:#CCCC00; margin:0; width:120px;
    text-align:center; float:left; margin:5px;}
    dt{ background:#CC0033;}dt img{display:block;
    margin:0 auto;}
    dd{ background:#FFFF00; }
    </style>
    HTML代码
    <h3>www.865171.cn</h3>
    <div id="box"> 
      <dl> 
        <dt> <img src="magicbean_070529.gif" /> </dt> 
        <dd>母亲节-祝福短信</dd> 
      </dl> 
      <dl> 
        <dt> <img src="magicbean_070529.gif" /> </dt> 
        <dd>母亲节-祝福短信</dd> 
      </dl> 
      <dl> 
        <dt> <img src="magicbean_070529.gif" /> </dt> 
        <dd>母亲节-祝福短信</dd> 
      </dl> 
      <dl> 
        <dt> <img src="magicbean_070529.gif" /> </dt> 
        <dd>母亲节-祝福短信</dd> 
      </dl> 
      <dl> 
        <dt> <img src="magicbean_070529.gif" /> </dt> 
        <dd>母亲节-祝福短信</dd> 
      </dl>   
    </div>改变div的宽度就可控制每行的数量
      

  4.   

    不知道有沒有放錯地方,好像行不通...<?php 
    header("Content-Type: text/html; charset=utf-8");
    require_once("connMysql.php");
    $pageRow_records = 8;
    $num_pages = 1;
    if (isset($_GET['page'])) {
      $num_pages = $_GET['page'];
    }$startRow_records = ($num_pages -1) * $pageRow_records;$query_RecAlbum = "SELECT `album`.`album_id` , `album`.`album_date` , `album`.`album_location` , `album`.`album_title` , `album`.`album_desc` , `albumphoto`.`ap_picurl`, count( `albumphoto`.`ap_id` ) AS `albumNum` FROM `album` LEFT JOIN `albumphoto` ON `album`.`album_id` = `albumphoto`.`album_id` GROUP BY `album`.`album_id` , `album`.`album_date` , `album`.`album_location` , `album`.`album_title` , `album`.`album_desc` ORDER BY `album_date` DESC";
    $query_limit_RecAlbum = $query_RecAlbum." LIMIT ".$startRow_records.", ".$pageRow_records;
    $RecAlbum = mysql_query($query_limit_RecAlbum);
    $all_RecAlbum = mysql_query($query_RecAlbum);
    $total_records = mysql_num_rows($all_RecAlbum);
    $total_pages = ceil($total_records/$pageRow_records);
    ?>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>私之網路相簿</title>
    </head><body><table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr><td><?php while($row_RecAlbum=mysql_fetch_assoc($RecAlbum)){ ?>
    <table width=90% align="left"  border="0" cellpadding="0" cellspacing="0"><tr><?php if($startRow_records>=4) { echo "<br>";?>
    <td><img src="images/frame1.png" width="196" height="35" /></td></tr>
    <tr><td><img src="images/frame3.png" width="39.5" height="108" /><a href="albumshow.php?id=<?php echo $row_RecAlbum["album_id"];?>"><?php if($row_RecAlbum["albumNum"]==0){?><img src="images/nopic.png" alt="暫無圖片" width="117" height="108" border="0" /><?php }else{?><img src="photos/<?php echo $row_RecAlbum["ap_picurl"];?>" alt="<?php echo $row_RecAlbum["album_title"];?>" width="117" height="108" border="0" /><?php }?></a><img src="images/frame4.png" width="39.5" height="108" /></div></td></tr>
    <tr><td><img src="images/frame2.png" width="195.9" height="28.5" /></td><?php }?>
    </tr>
    </table>
    <?php }?></td>
     </tr>
    </table>
    </body>
    </html>
      

  5.   

    不知道有沒有放錯地方,好像行不通...<?php 
    header("Content-Type: text/html; charset=utf-8");
    require_once("connMysql.php");
    $pageRow_records = 8;
    $num_pages = 1;
    if (isset($_GET['page'])) {
      $num_pages = $_GET['page'];
    }$startRow_records = ($num_pages -1) * $pageRow_records;$query_RecAlbum = "SELECT `album`.`album_id` , `album`.`album_date` , `album`.`album_location` , `album`.`album_title` , `album`.`album_desc` , `albumphoto`.`ap_picurl`, count( `albumphoto`.`ap_id` ) AS `albumNum` FROM `album` LEFT JOIN `albumphoto` ON `album`.`album_id` = `albumphoto`.`album_id` GROUP BY `album`.`album_id` , `album`.`album_date` , `album`.`album_location` , `album`.`album_title` , `album`.`album_desc` ORDER BY `album_date` DESC";
    $query_limit_RecAlbum = $query_RecAlbum." LIMIT ".$startRow_records.", ".$pageRow_records;
    $RecAlbum = mysql_query($query_limit_RecAlbum);
    $all_RecAlbum = mysql_query($query_RecAlbum);
    $total_records = mysql_num_rows($all_RecAlbum);
    $total_pages = ceil($total_records/$pageRow_records);
    ?>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>私之網路相簿</title>
    </head><body><table width="1000" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr><td><?php while($row_RecAlbum=mysql_fetch_assoc($RecAlbum)){ ?>
    <table width=90% align="left"  border="0" cellpadding="0" cellspacing="0"><tr><?php if($startRow_records>=4) { echo "<br>";?>   <<<<<<<<<<<<<<<<這裡
    <td><img src="images/frame1.png" width="196" height="35" /></td></tr>
    <tr><td><img src="images/frame3.png" width="39.5" height="108" /><a href="albumshow.php?id=<?php echo $row_RecAlbum["album_id"];?>"><?php if($row_RecAlbum["albumNum"]==0){?><img src="images/nopic.png" alt="暫無圖片" width="117" height="108" border="0" /><?php }else{?><img src="photos/<?php echo $row_RecAlbum["ap_picurl"];?>" alt="<?php echo $row_RecAlbum["album_title"];?>" width="117" height="108" border="0" /><?php }?></a><img src="images/frame4.png" width="39.5" height="108" /></div></td></tr>
    <tr><td><img src="images/frame2.png" width="195.9" height="28.5" /></td><?php }?>
    </tr>
    </table>
    <?php }?></td>
     </tr>
    </table>
    </body>
    </html>
      

  6.   

    <?php if($startRow_records>=4) { echo "<br>";?>
    <?php }?></td></tr>
    </table>
    <?php }?>改为</td></tr>
    </table>
    <?php if($startRow_records>=4) { echo "<br>";?>
    <?php }?>
    <?php }?>即,控制应在内部的表格结束后进行
      

  7.   

    你没有对 $startRow_records 赋值
      

  8.   

    你看這段代碼
    $startRow_records = ($num_pages -1) * $pageRow_records;
    $pageRow_records = 8;
    $num_pages = 1;
    if (isset($_GET['page'])) {
      $num_pages = $_GET['page'];
    }
    $num_pages 是取的當前頁的值,當前為第一頁時,你的$startRow_records 值是0,而你圖片換行的判斷是$startRow_records>=4,這個條件不能成立嘛當然不會換行了,你每行顯示8個是因為你的分頁程序$pageRow_records = 8。
    <?php if($startRow_records>=4) { echo "<br>";?>對不對