PHP如何检查它在记录中的最后一行?

时间:2011-11-14 09:18:58

标签: php mysql

大家好,祝大家好。 我有以下代码要从MYSQL中检索:

mysql_select_db($database_webiceberg, $webiceberg);
$query_services = "SELECT
services.id_services,
services.title,
services.body,
services.link,
services.cattegory,
services.service_cattegory,
services.page_title,
services.lang
from services
where lang=2 and 
cattegory='$webdesign'" ;
$services = mysql_query($query_services, $webiceberg) or die(mysql_error());
$row_services = mysql_fetch_assoc($services);
$totalRows_services =  mysql_num_rows($services);

在HTML中我有这个:

  <?php do { ?>
                  <!-- Content: Blog Page -->
                  <a name="blog_page" id="blog_page"></a>
                  <div class="ribbon">
                    <div class="wrapAround"></div>
                    <div class="tab">
                     <span name="<?php echo $row_services['title']; ?>">
                    <?php echo $row_services['title']; ?><a href='#Wrapper'>Top</a></span> 
                    </div>
                  </div>
                 <?php 

                 echo $row_services['body']; ?>
                  <p><br />


                    <a name="multi_column_page"></a>
                  </p>
                    <?php } while ($row_services = mysql_fetch_assoc($services)); ?>

Iam尝试将此行代码添加到查询<a href='#Wrapper'>Top</a>中的最终记录中 任何人都有想法如何在不添加额外查询的情况下做到这一点?

1 个答案:

答案 0 :(得分:2)

在第一组代码中,将$row_services重命名为$next_row

然后在do {之后,把它放在:

$row_services=$next_row;
$next_row=mysql_fetch_assoc($services);

然后您可以判断当前$row_services是否是最后一个,因为$next_row将为false。

while行替换为:

<?php } while ($next_row); ?>