Forum Moderators: coopster

Message Too Old, No Replies

Pagination - Change count

         

adammc

1:24 am on Mar 1, 2007 (gmt 0)

10+ Year Member



Hi guys,

Can anyone possibly help me with the output of the pagination links?
Its is currently displaying :

[PHP]Showing results 0 - 10 of 29
1 ¦ 2 ¦ 3 ¦ Next Page [/PHP]

I need it to display:
[PHP]Showing results '1' - 10 of 29
1 ¦ 2 ¦ 3 ¦ Next Page [/PHP]

[PHP]//define the no of rows per page
$rows_per_page = 10;

$query = "SELECT posting_id, vehicle_make, vehicle_model, expired, buyers_city, buyers_state, condition, category, description FROM postings WHERE status='open' ORDER BY expired";

// Run the query.
$result = @mysql_query ($query);
$total_records = mysql_num_rows($result);
$pages = ceil($total_records / $rows_per_page);
mysql_free_result($result);

// if there are more than 1 page run the query like this
if (!isset($filter))
$filter = 0;
$start = $filter * $rows_per_page ;


$query = "SELECT posting_id, vehicle_make, vehicle_model, expired, year, buyers_city, buyers_state, condition, category, description FROM postings WHERE status='open' ORDER BY expired, posting_id DESC LIMIT $start, $rows_per_page";

//the while loop
$result = @mysql_query ($query) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $query . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());

// Fetch and print all the records.
while($row=mysql_fetch_array($result))
{

// get the number of rows
$number = mysql_num_rows($result);


// content goes here ///

$showingto = ($start + $rows_per_page > $total_records)? $total_records : $start + $rows_per_page;

echo"<font class=\"gen\">";
echo "Showing results " . $start . " - " . $showingto . " of " . $total_records;
echo"</font><br><br>";

//showing the navigation links . (Previous)
if ($filter > 0) {
$previous = $filter - 1;
$url = $_SERVER['PHP_SELF'] . "?filter=$previous";
echo "<a href=\"$url\" class='gen'>Prev Page</a>&nbsp;¦&nbsp;\n";
}

// page numbering links
while ($i++<$pages){
$url = $_SERVER['PHP_SELF'] . "?filter=" . ($i-1);
echo $linknum = (($i-1)==$filter)? " $i ¦" : " <a href=\"$url\" class='gen'>$i</a> ¦";
}

//showing the navigation links . (Next)
if ($filter < $pages - 1) {
$next = $filter + 1;
$url = $_SERVER['PHP_SELF'] . "?filter=$next";
echo "<a href=\"$url\" class='gen'> Next Page</a>\n";
}[/PHP]

Any help would be greatly appreciated :)

eelixduppy

2:05 am on Mar 1, 2007 (gmt 0)



Do you just want the text to show correctly? Something like this?:

echo "Showing results " . ($start+1) . " - " . $showingto . " of " . $total_records;

I'm sorry if I misunderstood you. If you need more help with pagination, I wrote a little script [webmasterworld.com] awhile back that may provide useful to you. I referenced many good threads that you can check out, too.

Hope this helps! :)

adammc

2:53 am on Mar 1, 2007 (gmt 0)

10+ Year Member



Hi there eelixduppy,
thanks ofr the reply :)

I got the following with your suggestion:
Showing results 1 - of 29

Its not picking up the '. $showingto .'?

adammc

2:57 am on Mar 1, 2007 (gmt 0)

10+ Year Member



I figured it out, sorry my mistake!

I had placed this line below the echo statement!
$showingto = ($start + $rows_per_page > $total_records)? $total_records : $start + $rows_per_page;

Thanks for your help :)