2013-04-23 79 views
0

我有這張表,由於某種原因,沒有像我想要的那樣正確對齊。我有3列,1排。但是出於一些奇怪的原因,當我輸入東西時,它並不像它想象的那樣對齊。對齊表列PHP

<?php 

     $grab = mysql_query("SELECT * FROM topsongs ORDER BY number limit 10 ");  

      if (mysql_num_rows($grab)==0) { 
     echo "<div class='alert alert-note-x'>Sorry, it looks like their are no Top Songs Listed</div>"; 
    } 

     while($row = mysql_fetch_array($grab)){ 

     ?> 

<table style="border-spacing: 10px;width:100%;clear:both;overflow:hidden;border: 1px #EBEBEB solid;border-bottom: 2px #EBEBEB solid;padding:5px;margin-top:3px;margin-bottom:10px;" class="border-radius"> 
    <tr> 
     <td><?php echo stripslashes($row['number']); ?></td> 
     <td><img class="border-radius" width="70" height="70" src="<?php echo stripslashes($row['dpic']); ?>"></td> 
     <td><?php echo stripslashes($row['songname']); ?></td> 
    </tr> 
</table> 

     <?php } ?> 

你們碰巧知道它是什麼,我做錯了嗎? image here:http://screencloud.net/v/oN4l

+0

地方本在TD – 2013-04-23 04:17:25

+0

它如何對齊? – 2013-04-23 04:18:20

+1

[**請不要在新代碼中使用'mysql_ *'函數**](http://bit.ly/phpmsql)。他們不再被維護[並被正式棄用](https://wiki.php.net/rfc/mysql_deprecation)。看到[**紅框**](http://j.mp/Te9zIL)?學習[*準備的語句*](http://j.mp/T9hLWi),並使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [這篇文章](http://j.mp/QEx8IB)將幫助你決定哪個。如果你選擇PDO,[這裏是一個很好的教程](http://www.brightmeup.info/article.php?a_id=2)。 – 2013-04-23 04:18:52

回答

2

您爲每一行創建單獨的表。因此,對於每一行,計算列寬時不考慮其他行(在其他表中)。

<table>移至循環之前,將</table>移至循環之後,以便您只有一個包含所有行的表。在<td>

-1

使用align屬性一樣<td align="left">

0

下面是答案你想讓它

<?php 

     $grab = mysql_query("SELECT * FROM topsongs ORDER BY number limit 10 ");  

      if (mysql_num_rows($grab)==0) { 
     echo "<div class='alert alert-note-x'>Sorry, it looks like their are no Top Songs Listed</div>"; 
    } 
?> 

<table style="border-spacing: 10px;width:100%;clear:both;overflow:hidden;border: 1px #EBEBEB solid;border-bottom: 2px #EBEBEB solid;padding:5px;margin-top:3px;margin-bottom:10px;" class="border-radius"> 
<?php while($row = mysql_fetch_array($grab)){ ?> 
    <tr> 
     <td><?php echo stripslashes($row['number']); ?></td> 
     <td><img class="border-radius" width="70" height="70" src="<?php echo stripslashes($row['dpic']); ?>"></td> 
     <td><?php echo stripslashes($row['songname']); ?></td> 
    </tr> 
     <?php } ?> 
</table> 

替換您的代碼,並嘗試這個