Jump to content

Prev & Next Buttons on Top and Bottom of Lists


dmeeroff

Recommended Posts

Hey Eveyrone,

 

I'm new to PHP and was hoping someone could give me a hand here.

 

I'm building a page that lists information from a database, I'm able to get a previous & next button on the bottom of the page, but when I put the code for the button to go on the top of the page, it replicates the buttons for each listing it shows on the page.

 

Here is the page now: http://www.dangelorealty.com/listingsNW8.php

 

Does anyone know how I can just have the Prev/Next Buttons at the top of the page and the bottom of the page only?

 

Diego

Link to comment
Share on other sites

this page maybe helpful it displays next an previous records 69  per page

 

<?php session_start()?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

 

<style type="text/css">

<!--body{ margin: 0; padding:0; } div.lh-block1 a:link{color:blue;}

div.lh-block1 a:visited{color:purple;} div.rh-block

a:link{color:blue;} div.rh-block a:visited{color:purple;} div.full

a:link{color:blue;} div.full a:visited{color:blue;} a {

text-decoration: none; } #lh-col{ position:absolute; top:115px;

left:0; width:130px; z-index:3; border:1px solid black; } #rh-col{

position:absolute; top:115px; right:0; width:130px; z-index:2;

border:1px solid black; } .lh-block1{ position:absolute; left:7px;

height:298px; width:298px; font-size:14px; padding-left:10px; }

.lblock0{ position:absolute; left:25px; height:298px; width:100px;

padding-left:10px; font-size:14px; text-align:left; } .lblock1{ position:absolute;

left:169px; height:298px; width:100px; padding-left:10px;

font-size:14px; text-align:left;} .rh-block{ position:absolute; right:7px;

width:328px; z-index:2; font-size:14px; } .rblock0{

position:absolute; left:25px; height:298px; width:100px;

padding-left:10px; font-size:14px;text-align:left; } .rblock1{ position:absolute;

left:169px; height:298px; width:100px; padding-left:10px;

font-size:14px;text-align:left; } #lr-con{ width:100%; height:30%; } #c-block {

width:100%; z-index:1; height:80%; } .full{ height:29px; width:96%;

border-bottom:1px solid #9c9c9c; margin-top:10px; padding:10px; }

#hdr{ height:80px; width:100%; margin:0; } #nav{ height:25px;

width:100%; margin:0; background-color:black; } #sep{ width:100%;

height:10px; background-color:purple; margin:0; } #c-col0{ margin-left:auto;margin-right:auto;

width:675px; height:450px; position:relative;

z-index:5; background-image:

url("http://www.mydomain.com/currentwebsite/Images/htmlborder1.gif");

background-repeat: no-repeat; } #wrapper{width:738px;}

.Nav0{float:left;margin-right:3px;

padding:4px; color:white; height:20px; width:140px;} div a:link{color:white;} div a:visited

{color: white;} div.Nav0:hover{background-color:grey;} .Nav1{float:left;margin-left:3px;

padding:4px; height:20px; width:147px;  color:white; }

div.Nav1:hover{background-color:grey;} .Nav2{float:left;  height:20px;

width:100px; padding:4px; color:white; }

div.Nav2:hover{background-color:grey;} .Nav3{ float:left;  height:20px;

width:90px; padding:4px;

color:white; }

div.Nav3:hover{background-color:grey;}  .Nav4{float:left;margin-left:9px;

height:20px;width:119px;padding:4px;color:white; }

div.Nav4:hover{background-color:grey;} .Nav5{float:left;

height:20px; width:76px; padding:4px;color:white; }

div.Nav5:hover{background-color:grey;}

.ftr{text-align:center; width:100%;height:35px; border-top:1px solid black;}#req0{color:red;}

div.ftr a:link{color:blue;} div.ftr a:visited{color:blue;}-->

</style>

 

</head>

<body>

<?php

if (isset($_SESSION['adminid'])&&$_SESSION['adminid']=="8QdM8QdM"){?>

 

<div id="hdr" align="center"></div>

<div id="nav" align="center">

<div id="wrapper">

 

<div class ="Nav0" align="center"><a href="http://www.mydomain.com/currentwebsite/redirect_admin_register.html">

Model register

</a></div>

 

<div class="Nav1" align="center"><a href="http://www.mydomain.com/currentwebsite/redirect_client_main.html">

Current models

</a></div>

 

<div class="Nav2" align="center"><a href="https://www.mydomain.com/trans_redirect.html">

Add Funds

</a></div>

 

<div class="Nav3" align="center"><a href="http://www.mydomain.com/currentwebsite/acct_redirect.html">

Account

</a></div>

 

<div class="Nav4" align="center"><a href="http://www.mydomain.com/currentwebsite/redirect_admin_main.html">

Model login

</a></div>

 

<div class="Nav5" align="center"><a href="http://www.mydomain.com/currentwebsite/help_redirect.html">

Help

</a></div>

</div>

</div>

<div id="sep"></div>

 

<div id="c-block" align="center">

<div id="c-col0">

 

<div id ="lr-con">

<div class="full">View active profiles&nbsp

<?php include("../secure_php/admin_database.php");

 

 

$whopro = getlist();

if(isset($_GET['rnum'])){

$rnum =$_GET['rnum']+1;

}else{

$rnum=0;

}

 

 

if(isset($_GET['rnum'])){

$t=($rnum-1-1);

if($t==-1){

echo "<a href=\"http://www.mydomain.com/currentwebsite/accounts/profcontact.php\">Previous 69</a>&nbsp";

}else{

echo "<a href=\"http://www.mydomain.com/currentwebsite/accounts/profcontact.php?rnum=$t\">Previous 69</a>&nbsp";

 

}

}

 

 

 

if(($rnum*68)+68<count($whopro)){

echo "<a href=\"http://www.mydomain.com/currentwebsite/accounts/profcontact.php?rnum=$rnum\">Next 69</a>";

}

 

?>

 

 

</div>

 

 

<div class="lh-block1">

<div class="lblock0">

<?php

 

for($l=0; $l < 17; $l++){

$i=($rnum*68) + $l;

 

if(!isset($whopro[$i])) break;

echo "<a href=\"http://www.mydomain.com/currentwebsite/privprofiles/$whopro[$i].html\" name=\"[$i]\">$whopro[$i]</a><br />";

 

}

?>

</div>

 

<div class="lblock1">

<?php

for($l=17; $l < 34; $l++){

$i=($rnum*68) + $l;

if(!isset($whopro[$i])) break;

 

 

echo "<a href=\"http://www.mydomain.com/currentwebsite/privprofiles/$whopro[$i].html\" name=\"[$i]\">$whopro[$i]</a><br />";

 

}

?>

</div>

</div>

 

<div class="rh-block">

<div class="rblock0">

<?php

 

for($l=34; $l < 51; $l++){

$i=($rnum*68) + $l;

if(!isset($whopro[$i])) break;

echo "<a href=\"http://www.mydomain.com/currentwebsite/privprofiles/$whopro[$i].html\" name=\"[$i]\">$whopro[$i]</a><br />";

}

?>

</div>

<div class="rblock1">

<?php

 

for($l=51; $l < 68; $l++){

$i=($rnum*68) + $l;

if(!isset($whopro[$i])) break;

echo "<a href=\"http://www.mydomain.com/currentwebsite/privprofiles/$whopro[$i].html\" name=\"[$i]\">$whopro[$i]</a><br />";

}

?>

</div>

</div>

 

</div>

</div>

</div>

Link to comment
Share on other sites

calmchess: when you posting code, ESPECIALLY that much please use the code tags..

nonetheless that doesnt help the OP at all as he already has pagination he just has an output problem with the buttons..

 

How are you trying to put the code in here?

Link to comment
Share on other sites

You need to move this codeblock

<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="20" height="20" align="center" valign="top"> </td>
    <td height="20" colspan="10" align="left" valign="top" bgcolor="#000000" class="box-headers2"><?if($pg > 1){?><input class="orange" type="button" onClick="location.href='<?=($_SERVER[sCRIPT_NAME].$qs_no_pg."pg=".($pg-1))?>';" value="<<Prev"><?}?></td>
    <td height="20" colspan="18" align="center" valign="top" bgcolor="#000000" class="box-headers2"><?=$pos+1?> to <?if(($pos+$listings_per_page) > $list_count){echo $list_count;}else{echo $pos+$listings_per_page;}?> of <?=$list_count?></td>
    <td height="20" colspan="10" align="right" valign="top" bgcolor="#000000" class="box-headers2"><?if($pg < $max_page){?><input class="orange" type="button" onClick="location.href='<?=($_SERVER[sCRIPT_NAME].$qs_no_pg."pg=".($pg+1))?>';" value="Next>>"><?}?></td>
    <td width="20" height="20" align="center" valign="top"> </td>
  </tr>
</table>

to outside of your while loop..

Link to comment
Share on other sites

How far did you move it?

	while($list_data = mysql_fetch_array($result))
{
?>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="20" height="20" align="center" valign="top"> </td>
    <td height="20" colspan="10" align="left" valign="top" bgcolor="#000000" class="box-headers2"><?if($pg > 1){?><input class="orange" type="button" onClick="location.href='<?=($_SERVER[sCRIPT_NAME].$qs_no_pg."pg=".($pg-1))?>';" value="<<Prev"><?}?></td>
    <td height="20" colspan="18" align="center" valign="top" bgcolor="#000000" class="box-headers2"><?=$pos+1?> to <?if(($pos+$listings_per_page) > $list_count){echo $list_count;}else{echo $pos+$listings_per_page;}?> of <?=$list_count?></td>
    <td height="20" colspan="10" align="right" valign="top" bgcolor="#000000" class="box-headers2"><?if($pg < $max_page){?><input class="orange" type="button" onClick="location.href='<?=($_SERVER[sCRIPT_NAME].$qs_no_pg."pg=".($pg+1))?>';" value="Next>>"><?}?></td>
    <td width="20" height="20" align="center" valign="top"> </td>
  </tr>
</table>

 

to

?>
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="20" height="20" align="center" valign="top"> </td>
    <td height="20" colspan="10" align="left" valign="top" bgcolor="#000000" class="box-headers2"><?if($pg > 1){?><input class="orange" type="button" onClick="location.href='<?=($_SERVER[sCRIPT_NAME].$qs_no_pg."pg=".($pg-1))?>';" value="<<Prev"><?}?></td>
    <td height="20" colspan="18" align="center" valign="top" bgcolor="#000000" class="box-headers2"><?=$pos+1?> to <?if(($pos+$listings_per_page) > $list_count){echo $list_count;}else{echo $pos+$listings_per_page;}?> of <?=$list_count?></td>
    <td height="20" colspan="10" align="right" valign="top" bgcolor="#000000" class="box-headers2"><?if($pg < $max_page){?><input class="orange" type="button" onClick="location.href='<?=($_SERVER[sCRIPT_NAME].$qs_no_pg."pg=".($pg+1))?>';" value="Next>>"><?}?></td>
    <td width="20" height="20" align="center" valign="top"> </td>
  </tr>
</table><?php
while($list_data = mysql_fetch_array($result))
{
?>

Should work...

Link to comment
Share on other sites

The query you are using the get the count has a different WHERE clause than the actual results..

This could be your problem..

 

You can shrink this code down

$sql = "SELECT count(id) FROM items WHERE enabled = 'Y'";
	$result = mysql_query($sql);
	echo mysql_error();
	$list_count = mysql_result($result, 0);
	$max_page = ceil($list_count / 10);

	$sql = "SELECT id, low_price, price, item_type, short_desc, status, sale_comment, cat_list, bedrooms, bathrooms, sq_ft_ttl, main_photo, other_photo1, other_photo2, other_photo3, other_photo4, other_photo5 FROM items WHERE enabled = 'Y' AND `status` NOT IN ('Leased', 'For Lease')  ORDER BY price DESC LIMIT $pos, $listings_per_page";
	$result = mysql_query($sql);
	echo mysql_error();

to

$sql = "SELECT id, low_price, price, item_type, short_desc, status, sale_comment, cat_list, bedrooms, bathrooms, sq_ft_ttl, main_photo, other_photo1, other_photo2, other_photo3, other_photo4, other_photo5 FROM items WHERE enabled = 'Y' AND `status` NOT IN ('Leased', 'For Lease')  ORDER BY price DESC LIMIT $pos, $listings_per_page";
	$result = mysql_query($sql);
$list_count = mysql_num_rows($result)
	$max_page = ceil($list_count / 10);

there is no need to use 2 queries

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.