duanduoding2238 2012-03-20 14:41
浏览 27
已采纳

表行彼此相邻

I tried to allow the last td in this code to be beside the previous td, but I can't and the td is printed in a new line. How to allow them to be beside each other,the problem is that the 1st 5 td are in a foreach loop and the last td is not follow this foreach as it's value is a function and not a key or a value in the foreach.

<?php foreach($downloads as $dl) { ?>
<tr id="this">
 <td ><img src="images/<?=$dl['type']?>.png"/></td> 
 <td id="no3"><?=$dl['type']?></td>
 <td>
  <a target="_blank" style="margin-right:3px" href="download.php?id=<?=$dl['id']?>">
   <?=$dl['title']?>
  </a>
 </td>
 <td>
  <center>
   <a href="http://<?=urlencode($dl['surl'])?>"><?=$dl['sname']?></a>
  </center>
 </td>
 <td align="center"><?=$dl['views']?></td>
</tr>
<?php } ?>


  <td  align="center"><?=$core->use_love(); ?></td> 

http://advphp.com/imgup/images/41553286204776144664.jpghttp://advphp.com/imgup/images/86639621977227017216.jpg

The function of the last td

    public function use_love(){

    $sql=mysql_query("select * from wcddl_downloads ORDER BY id DESC LIMIT ".$this->pg.",".$this->limit."");

    while($row=mysql_fetch_array($sql))
    {
    $down_id=$row['id'];
    $love=$row['love'];
    ?>
    <div class="box" align="center">
    <a href="#" class="love" id="<?php echo $down_id; ?>">
    <span class="on_img" align="left"> <?php echo $love; ?> </span> 
    </a>
    </div>
    <?
    }               
 }
  • 写回答

2条回答 默认 最新

  • douhuang3833 2012-03-20 14:53
    关注

    The last <td> (the one outside the foreach loop) is on a new line because it's outside the last <tr> tag. One way to solve this is to always close the </tr> tag after the last <td>, like this:

    <?php
    $first_time = True;
    foreach($downloads as $dl) {
        // If this is the first time through the loop, don't echo a </tr> tag:
        if ($first_time) {
            $first_time = False;
        } else {
            echo "</tr>";
        }
    
        // Now print the new row, but don't close it yet:
    ?>
    
    <tr id="this">
      <td><img src="images/<?=$dl['type']?>.png"/></td> 
      <td id="no3"><?=$dl['type']?></td>
      <td><a target="_blank" style="margin-right:3px" href="download.php?id=<?=$dl['id']?>"><?=$dl['title']?></a></td>
      <td><center><a href="http://<?=urlencode($dl['surl'])?>"><?=$dl['sname']?></a></center></td>
      <td align="center"><?=$dl['views']?></td>
    
    <?php
    }
    ?>
    
    <td align="center"><?=$core->use_love(); ?></td> 
    </tr>
    

    This will always put the last <td> in the final row.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Qt安装后运行不了,这是我电脑的问题吗
  • ¥15 数据量少可以用MK趋势分析吗
  • ¥15 使用VH6501干扰RTR位,CANoe上显示的错误帧不足32个就进入bus off快慢恢复,为什么?
  • ¥15 大智慧怎么编写一个选股程序
  • ¥100 python 调用 cgps 命令获取 实时位置信息
  • ¥15 两台交换机分别是trunk接口和access接口为何无法通信,通信过程是如何?
  • ¥15 C语言使用vscode编码错误
  • ¥15 用KSV5转成本时,如何不生成那笔中间凭证
  • ¥20 ensp怎么配置让PC1和PC2通讯上
  • ¥50 有没有适合匹配类似图中的运动规律的图像处理算法