...

View Full Version : Pagination - Change count



adammc
03-01-2007, 02:24 AM
Hi guys,

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


Showing results 0 - 10 of 29
1 | 2 | 3 | Next Page

I need it to display:

Showing results '1' - 10 of 29
1 | 2 | 3 | Next Page




//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";
}

Any help would be greatly appreciated :)

BonRouge
03-01-2007, 02:52 AM
You could do this:

echo "Showing results " . $start . " - " . $showingto . " of " . $total_records;
to this:


echo "Showing results " . (($start=='0')? '1' : $start) . " - " . $showingto . " of " . $total_records;

It won't be right though. If it says '0-10', it means you have 11 results. Doing what I'm saying here will mean you have '1-10' with 11 results. If you don't mind that, then go ahead.

adammc
03-01-2007, 02:56 AM
Hi BonRouge,
Thanks for the reply :)

So to get it 'correct' I would need to completely recode (start from scratch)?

BonRouge
03-01-2007, 03:03 AM
I'm sorry - no.
Just do this:

echo "Showing results " . ($start+1) . " - " . ($showingto+1) . " of " . $total_records;
I think that should work.

(Maybe I should have some breakfast before I switch on my computer...)

adammc
03-01-2007, 03:14 AM
:) do the same thing here, usually even forget my coffee!

Ok the result was:
Showing results 1 - 1 of 29

BonRouge
03-01-2007, 03:45 AM
Well, that doesn't make sense. If $showingto is 10, then $showingto+1 is 11.
Maybe someone smarter than me should help you. I'm going for breakfast.

adammc
03-01-2007, 03:57 AM
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 :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum