/    Sign up×
Community /Pin to ProfileBookmark

Pagination don’t show next if no more results

I have this little pagination script and it works for the most part. but right now I am trying to get it to only show a “Previous” link if there is rows before and Next only if rows after the limit specified.

I got it to not show the previous link when no rows before but it won’t show next and previous on the next page only previous. which leads me to believe it is a if{}else{} failure on my part. but where? and how can I accomplish this if how I am doing it is wrong.

the code in question. (snippets of the important stuff)

[code=php]
$table_name = “guestbook”;
$table_2 = “guest_comments”;
$show = 6;
$start = (isset($_GET[‘start’]))?$_GET[‘start’]:0;
/////////
$sql2 = mysql_query(“SELECT COUNT(*) FROM $table_name”);
$howmany = mysql_fetch_row($sql2) or die(“Error Line 8.” . mysql_error());
global $guest_block;

$guest_block = “<table class=”gbook” width=”70%” align=”center” cellpadding=”5″ cellspacing=”0″>”;
$sql = “SELECT * FROM $table_name ORDER BY id DESC LIMIT $start, $show”;
$result = mysql_query($sql, $connection) or die (mysql_error());
$count = 0;
while($row = mysql_fetch_array($result)) {

$count++;
// get individual elements from the array
// all kinds of elements here…
}
////////
//after the while then I have this portion again to build the link.
////////
$total = $start + $show;
$next = $start + $show;
$prev = $start – $show;
////////
if(($total < $howmany[0]) && ($prev > 0))
{
$guest_block .= ”
<div align=”center”>
<a href=”$_SERVER[PHP_SELF]?start=$prev”>Previous $show</a>
| <a href=”$_SERVER[PHP_SELF]?start=$next”>Next $show</a>
</div>
<p>Showing Listings $start to $total of $howmany[0].</p>”;
}

if ($prev < 0)
{
$guest_block .= ”
<div align=”center”>
<a href=”$_SERVER[PHP_SELF]?start=$next”>Next $show</a>
</div>
<p>Showing Listings $start to $total of $howmany[0].</p>”;

}
else
{
$guest_block .= ”
<div align=”center”>
<a href=”$_SERVER[PHP_SELF]?start=$prev”>Previous $show</a>
</div>
<p>Showing Listings $start to $total of $howmany[0].</p>”;
}

}

[/code]

Please any help will be appreciated. I can’t have it just always display a link because it is a bad query if there are no rows left or none previous to what is currently being shown…

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@Markbad311authorFeb 28.2006 — to reinterate it seems that only the last if {} block is working.

I need an if else block that is like this

if (from 0-10 rows){

No previous link

}

elseif (10 -2nd to last set of results) {

// show next AND previous links.

}

else (2nd to last set-no more rows left) {

// Only previous link

}

Thanks.
Copy linkTweet thisAlerts:
@Markbad311authorMar 01.2006 — <BUMP>

Still definetly need some help on this one. Please anyone that has any idea how I an remedy this issue please do... Many Thanks.. ?
Copy linkTweet thisAlerts:
@Markbad311authorMar 01.2006 — <BUMP>

is this an imposible thing to do or something?
×

Success!

Help @Markbad311 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...