Skip to main content
Inspiring
April 21, 2009
Question

how to display first record from recordset differently

  • April 21, 2009
  • 1 reply
  • 481 views

In a table called news, I have for example 100 records of which I want to show only the last 5 on a news page. In order to set up a news page, I'd like to have the latest news item displayed differently than the other items. I put the code below because otherwise it gets too confusing maybe. As you can see below, every record is put into a div with a h3 tag for the title and a p tag for the content. But what I would like to have is that the latest message displays for example like this:

<div class=”newsitem1”>

<h1><?php echo $row_news ['titel']; ?></h1>

<!--with great thanks to this forum for this piece of code-->

<p><?php $string = $row_news['inleiding'];

$space = strpos($string, ' ', 100);

echo substr($string, 0, $space) . '...'; ?></p>

</div>

<div class=”newsitemother”>

<h3>other titles</h3>

<p><?php $string = $row_news['inleiding'];

$space = strpos($string, ' ', 100);

echo substr($string, 0, $space) . '...'; ?></p>

</div>

Up to the point where I get stuck, I have the following piece of code:

$maxRows_news = 5;

$pageNum_news = 0;

if (isset($_GET['pageNum_news'])) {

  $pageNum_news = $_GET['pageNum_news'];

}

$startRow_news = $pageNum_news * $maxRows_news;

mysql_select_db($database_connjvb, $connjvb);

$query_news = "SELECT * FROM nieuws ORDER BY nr DESC";

$query_limit_news = sprintf("%s LIMIT %d, %d", $query_news, $startRow_news, $maxRows_news);

$news = mysql_query($query_limit_news, $connjvb) or die(mysql_error());

$row_news = mysql_fetch_assoc($news);

if (isset($_GET['totalRows_news'])) {

  $totalRows_news = $_GET['totalRows_news'];

} else {

  $all_news = mysql_query($query_news);

  $totalRows_news = mysql_num_rows($all_news);

}

$totalPages_news = ceil($totalRows_news/$maxRows_news)-1;

?>

<?php do { ?>

<div class="newsitem1">

<h1><?php echo $row_news ['titel']; ?></h1>

<!--with great thanks to this forum for this piece of code-->

<p><?php $string = $row_news['inleiding'];

$space = strpos($string, ' ', 100);

echo substr($string, 0, $space) . '...'; ?></p>

</div>

<?php } while ($row_news = mysql_fetch_assoc($news)); ?>

This topic is closed to new replies. Start a new post to keep the conversation going.

1 reply

Randy Edmunds
Adobe Employee
Adobe Employee
April 22, 2009

In your loop where your reading in your records, add a counter so you can determine which record is the first.

For the first record, give it a class of "newsitem1" and give all of your other records a class of something like "newsitemOther".

Then create CSS class selectors appropriately.

HTH,

Randy