Gunnit
Gunnit

Reputation: 1074

PHP how to check it its the final row in a record?

Hello and good day to all. I have the following code to retrieve from 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);

In the HTML I have this :

  <?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 trying to add this line of code only to the final reccord in the query <a href='#Wrapper'>Top</a> Anybody has ideas how i could do that without adding additional queries ?

Upvotes: 0

Views: 62

Answers (1)

Kae Verens
Kae Verens

Reputation: 4079

in the first set of code, rename $row_services to $next_row

then just after do {, put this:

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

then you can tell if the current $row_services is the last, because $next_row will be false.

replace the while line with this:

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

Upvotes: 2

Related Questions