Hi all,
I currently have a next/previous script that works just fine but i want to make a slight modification. I've tried several times to tweek it but to no avail.
At the moment, if $totalrows equals lets say 523 the page results equal 53. There are too many page links displayed across the screen.
Can anyone tell me how to get it to display the first 20 page links if the $totalrows >= 201 (or if $numofpages >= 20)?
The remaining results will display in multiples of ten
eg.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 30 40 50
If the user clicks on 20 the page results will look like
1 2 3 4 5 6 7 8 9 10 20 21 22 23 24 25 26 27 28 29 30 40 50
If the user clicked on the 40 then the page results would look like
1 2 3 4 5 6 7 8 9 10 20 30 40 41 42 43 44 45 46 47 48 49 50
I hope that makes sense.
Any ideas on how to achieve this?
Here is the code:
<?
$limit = 10;
$query_count = " SELECT * FROM movie_genre WHERE genre_id='$list_id'";
$result_count = mysql_query($query_count);
$totalrows = mysql_num_rows($result_count);
while ($row1 = mysql_fetch_array($result_count)) {
$new_genre_id = $row1["genre_id"];
}
if(empty($page))
$page = 1;
$limitvalue = $page * $limit - ($limit);
if($sortby == 'top_sellers'){
$query = "SELECT * FROM movie, orders WHERE movie.movie_id=orders.movie_id
ORDER BY movie.movie_title LIMIT $limitvalue, $limit";
} else if($sortby == 'member_ratings'){
$query = "SELECT * FROM movie, movie_genre WHERE movie.movie_id=movie_genre.movie_id
AND movie_genre.genre_id='$new_genre_id' ORDER BY member_ratings LIMIT $limitvalue, $limit";
} else if($sortby == 'title'){
$query = "SELECT * FROM movie, movie_genre WHERE movie.movie_id=movie_genre.movie_id
AND movie_genre.genre_id='$new_genre_id' ORDER BY movie_title LIMIT $limitvalue, $limit";
} else if($sortby == 'actor'){
$query = "SELECT * FROM movie, movie_genre WHERE movie.movie_id=movie_genre.movie_id
AND movie_genre.genre_id='$new_genre_id' ORDER BY last_name LIMIT $limitvalue, $limit";
} else {
$query = "SELECT * FROM movie, movie_genre WHERE movie.movie_id=movie_genre.movie_id
AND movie_genre.genre_id='$new_genre_id' ORDER BY movie_title DESC LIMIT $limitvalue, $limit";
}
$result = mysql_query($query) or die("Error: " . mysql_error());
$totalpagerows = mysql_num_rows($result);
?>
<TABLE cellSpacing=0 cellPadding=0 border=0>
<TR>
<TD width=10 colSpan=3 height=15><SPACER height="15" width="10" type="block"></TD>
</TR>
</TABLE>
<table width="580" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><hr width="100%" size="1"></td>
</tr>
<tr>
<td valign="top">
<TABLE width="100%" border=0 cellPadding=0 cellSpacing=0>
<TR>
<TD class=btextwhitebg noWrap>Skip to Page
<?
if($page != 1)
$pageprev = $page - 1;
$numofpages = ceil($totalrows / $limit);
for($i = 1; $i <= $numofpages; $i++){
if($i == $page)
echo "$i "; //active
else
echo("<a href=\"genre_list.php?list_id=$list_id&sortby=$sortby&page=$i\">$i</a> "); //non active
}
if($numofpages != 1){
if($i == $page)
echo "$i"; //active
}else if($totalpagerows != $limit){
//echo("$i"); //active
}else
echo("<a href=\"genre_list.php?list_id=$list_id&sortby=$sortby&page=$i\">$i</a>"); //non active
if(($totalrows - ($limit * $page)) > 0){
$pagenext = $page + 1;
?>
</TD>
<TD class=btextwhitebg align=right>
<?
if($page != 1){
$pageprev = $page - 1;
echo("<a href=\"genre_list.php?list_id=$list_id&sortby=$sortby&page=$pageprev\">Previous</a> ");
}else
echo(" ");
?>
<?
echo("<a href=\"genre_list.php?list_id=$list_id&sortby=$sortby&page=$pagenext\">Next</a>");
}else if($totalpagerows != $limit){
if(!$_GET['page']){
} else {
echo(" </TD><TD class=btextwhitebg align=right><a href=\"genre_list.php?list_id=$list_id&sortby=$sortby&page=$pageprev\">Previous</a>");
}
}
?>
</TD>
</TR>
<TR>
<TD height=3></TD>
</TR>
<TR>
<TD class=btextwhitebg width=200>Items
<? echo ($page * $limit) - ($limit - 1) ?>
-
<? echo ($page * $limit) + ($totalpagerows - $limit) ?>
of
<? echo $totalrows ?>
Results</TD>
<tr>
<td colspan="2"></td>
</TR>
<TR></TR>
</TABLE></td>
</tr>
<tr>
<td><hr width="100%" size="1"></td>
</tr>
</table>
Cheers,
micmac