开发者

Table inside a loop

开发者 https://www.devze.com 2022-12-22 16:18 出处:网络
I have one table in loop which come under li: 开发者_JAVA技巧<?php for($i=1;$i<=$tc;$i++) {

I have one table in loop which come under li:

开发者_JAVA技巧
<?php
 for($i=1;$i<=$tc;$i++)
 {
  $row=mysql_fetch_array($result);
  ?>
  <li style="list-style:none; margin-left:-20px">
  <table width="600" border="0" cellspacing="0" cellpadding="0">
  <tr>
 <td class="hline" style="width:267px"><?php  echo $row['tit'] .",". $row['name'] ?></td>
<td class="vline" style="width:1px">&nbsp;</td>
<td class="hline" style="width:100px"><?php echo $row['city']; ?></td>
  </tr>
 </table>
</li>
<?php
}
?>

The output comes like this:

alt text http://img20.imageshack.us/img20/4153/67396040.gif

  • I can't put table outside the loop, due to <li> sorting


if you can't use table outside the loop then i think best option will be use of

     <div>

statement

for example

   <div class="q-s na">
     <div class="st" style="margin-right:10px; width:150px">
        <div class="m-c"><?php  echo $row['tit'] .",". $row['name'] ?></div>
    </div>

this will be same as you one

      <td>

you can define style according to your requirements.

for example

        <style>
    .q-s{overflow:hidden;width:664px;float:left; 
         padding-top:2px; padding-bottom:2px; height:25px}

      .na .st{ float:left;}
   .na .m-c {border-bottom:1px dotted #999; padding-bottom:10px; height:15px}
    </style>


i can't put table outside the loop.

Why not? This is where it belongs. After all, you (logically) produce one table, not many of them. No need for the list item, either.


If you're unable to put the table outside of the loop, you should probably just use tags rather than creating tables, as you're defeating the purpose of even having a table by making each table a single row and trying to stack them.

Another thing to note if you are going to stick with tables:

If you're hard-coding the table width AND all of the table cell (column) widths, it may cause unexpected issues when they don't add up:

Table width = 600px

Cells = 267 + 1 + 100 = 368px

0

精彩评论

暂无评论...
验证码 换一张
取 消