2010-10-31 79 views
0
<table border="0" cellspacing="0" cellpadding="0" > 
<tr> 
<?php 
while ($pF = mysql_fetch_array($stringVisits)) { 
?> 
<td class="viewercell" style="color: #CCC; font-size: 10px;"> 
<?php 
echo "<a href='profil.php?id=".$BuID."'>"; 
echo "<img style='margin-right: 5px; width: 61px; height: 80px;'"; 

if (checkStatus($BuID) == 1) { 
    echo 'class="onlineBorder" '; 
} else { 
    echo 'class="image-xxsmall-border" '; 
} 
echo " src='images/profilePhoto/thumbs/"; 
if (!empty($getByProfile["photo_thumb"])) { 
    echo $getByProfile["photo_thumb"]; 
} else { 
    echo "noPhoto_thumb.jpg"; 
} 
echo "'>"; 
?> 
</a> 
</td> 

<?php } ?> 
</tr> 
</table> 

這就是我現在所顯示的訪問者的profileimage。現在我想要在圖片下面顯示他們的名字..但是之後我需要在此之後創建另一個<tr>,並在每個<td>中添加他們的名字。但是,如果我有這個時間,我該怎麼做呢?我應該再運行一次,獲取名字還是我可以做一些聰明的事情?PHP:用tr和td一起使用while()

回答

0

爲什麼不把名稱粘貼在與圖像相同的單元格中?關閉圖片標籤後,只需echo $ getByProfile [「username」]或其他什麼?

<table border="0" cellspacing="0" cellpadding="0" > 
<tr> 
<?php 
while($pF = mysql_fetch_array($stringVisits)){ 
?> 
<td class="viewercell" style="color: #CCC; font-size: 10px;"> 
<?php 
echo "<a href='profil.php?id=".$BuID."'>"; 
echo "<img style='margin-right: 5px; width: 61px; height: 80px;'"; 

          if(checkStatus($BuID) == 1){ 
          echo 'class="onlineBorder" '; 
          } else { 
          echo 'class="image-xxsmall-border" '; 
          } 
echo " src='images/profilePhoto/thumbs/"; 
if(!empty($getByProfile["photo_thumb"])) { echo $getByProfile["photo_thumb"]; }else{ 
echo "noPhoto_thumb.jpg"; 
} 
echo "'><br/>"; 
?> 
</a> 
<br/><?php echo $getByProfile['username']; ?> 
</td> 

<?php } ?> 
</tr> 
</table> 
0

這可能不太好,但它應該工作爲什麼你想要2循環?

<?php 
echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" >"; 
while($pF = mysql_fetch_array($stringVisits)){ 
echo " 
<tr> 
<td class="viewercell" style="color: #CCC; font-size: 10px;"> 
    <a href='profil.php?id=".$BuID."'> <img /> </a> 
</td> 
</tr> 
<tr><td> " . $getByProfile['username'] . " </td></tr>"; 

} 
echo "</table>"; 
?> 
+0

該表將與所有行相乘,我希望它們都在1個表內。 – Johnson 2010-10-31 22:54:42

+0

將表格標籤放在循環之外我會編輯它,以便您可以看到 – Mars 2010-10-31 23:13:52

0

這裏是一種以最小的改動現有代碼做到這一點:

<?php 
<table border="0" cellspacing="0" cellpadding="0" > 
<tr> 
<?php 
$names = array(); // ADDITION #1 
while($pF = mysql_fetch_array($stringVisits)){ 
    $names[] = // ADDITION #2 - ADD NEW USER NAME HERE; 
?> 
<td class="viewercell" style="color: #CCC; font-size: 10px;"> 
<?php 
echo "<a href='profil.php?id=".$BuID."'>"; 
echo "<img style='margin-right: 5px; width: 61px; height: 80px;'"; 

          if(checkStatus($BuID) == 1){ 
          echo 'class="onlineBorder" '; 
          } else { 
          echo 'class="image-xxsmall-border" '; 
          } 
echo " src='images/profilePhoto/thumbs/"; 
if(!empty($getByProfile["photo_thumb"])) { echo $getByProfile["photo_thumb"]; }else{ 
echo "noPhoto_thumb.jpg"; 
} 
echo "'>"; 
?> 
</a> 
</td> 

<?php } 

// ADDITION #3: 
echo "</tr> 
<tr>"; 

foreach ($names as $username) 
    echo "<td class=\"username\"><p>$username</p></td>"; 

?> 

</tr> 
</table> 

另外請注意,你有你的代碼的方式,</tr>while循環中。