Forum Moderators: coopster

Message Too Old, No Replies

Limiting Records

         

phprockz

9:03 pm on Apr 18, 2006 (gmt 0)

10+ Year Member



I have 50 records.I displayed all records in page using Dynamic table repeated region using dreamweaver.

Here is the code.

<?

$maxRows_rslatestnews = 17;
$pageNum_rslatestnews = 0;
if (isset($_GET['pageNum_rslatestnews'])) {
$pageNum_rslatestnews = $_GET['pageNum_rslatestnews'];
}
$startRow_rslatestnews = $pageNum_rslatestnews * $maxRows_rslatestnews;

mysql_select_db($database_connection, $connection);
$query_rslatestnews = "SELECT * FROM news_article_art INNER JOIN news_topic_top ON idtop_art=id_top WHERE idtop_art = '1' ORDER BY date_art DESC";
$query_limit_rslatestnews = sprintf("%s LIMIT %d, %d", $query_rslatestnews, $startRow_rslatestnews, $maxRows_rslatestnews);
$rslatestnews = mysql_query($query_limit_rslatestnews, $connection) or die(mysql_error());
$row_rslatestnews = mysql_fetch_assoc($rslatestnews);

if (isset($_GET['totalRows_rslatestnews'])) {
$totalRows_rslatestnews = $_GET['totalRows_rslatestnews'];
} else {
$all_rslatestnews = mysql_query($query_rslatestnews);
$totalRows_rslatestnews = mysql_num_rows($all_rslatestnews);
}
$totalPages_rslatestnews = ceil($totalRows_rslatestnews/$maxRows_rslatestnews)-1;
?>

<?php do {?>
<?php echo $row_rslatestnews['title_art'];?>
<?php } while ($row_rslatestnews = mysql_fetch_assoc($rslatestnews));?>

<?
mysql_free_result($rslatestnews);

<?
This is printing all my records.What i required is to be diplayed from 5th record onwards ie, 5- 50 records should be displayed.How can i do like that please suggest.

supermanjnk

12:17 pm on Apr 19, 2006 (gmt 0)

10+ Year Member



to limit a query you need to have
LIMIT 5
in your query (at the end I think or thats where I always put it)
Where 5 is the number you want to limit by, if you want to start at a certain record you would need to have
LIMIT 5,50
this will start at record 5 and display up to 50 records.

Is that what you are looking for?