dmeeroff Posted January 18, 2010 Share Posted January 18, 2010 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 Quote Link to comment Share on other sites More sharing options...
Buddski Posted January 18, 2010 Share Posted January 18, 2010 It appears to me you have the button code running with every iteration of your loop. Can you post your code please. Quote Link to comment Share on other sites More sharing options...
calmchess Posted January 18, 2010 Share Posted January 18, 2010 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  <?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> "; }else{ echo "<a href=\"http://www.mydomain.com/currentwebsite/accounts/profcontact.php?rnum=$t\">Previous 69</a> "; } } 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> Quote Link to comment Share on other sites More sharing options...
dmeeroff Posted January 18, 2010 Author Share Posted January 18, 2010 Thank you for the quick replies. How do I get the buttons out of the loop. I'm trying to place the code in here, but for some reason, it won't let me. Diego Quote Link to comment Share on other sites More sharing options...
Buddski Posted January 18, 2010 Share Posted January 18, 2010 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? Quote Link to comment Share on other sites More sharing options...
dmeeroff Posted January 18, 2010 Author Share Posted January 18, 2010 I'm just copying & pasting my code. Diego Quote Link to comment Share on other sites More sharing options...
Buddski Posted January 18, 2010 Share Posted January 18, 2010 I dont see why it wouldnt be working.. try attaching your code to the topic.. Quote Link to comment Share on other sites More sharing options...
dmeeroff Posted January 18, 2010 Author Share Posted January 18, 2010 Okay, here it is attached. Diego [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
Buddski Posted January 18, 2010 Share Posted January 18, 2010 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.. Quote Link to comment Share on other sites More sharing options...
dmeeroff Posted January 18, 2010 Author Share Posted January 18, 2010 Okay, when I do that, this is what it looks like: http://www.dangelorealty.com/listingsNW9.php The buttons don't appear because the code is getting any info from the database. Diego Quote Link to comment Share on other sites More sharing options...
deansatch Posted January 18, 2010 Share Posted January 18, 2010 They are at the bottom and when you click next, the "previous" button appears at the top - only the next button is missing from the top. Quote Link to comment Share on other sites More sharing options...
Buddski Posted January 18, 2010 Share Posted January 18, 2010 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... Quote Link to comment Share on other sites More sharing options...
dmeeroff Posted January 18, 2010 Author Share Posted January 18, 2010 That seems to have done it! Thank you so much, Diego Quote Link to comment Share on other sites More sharing options...
calmchess Posted January 18, 2010 Share Posted January 18, 2010 btw very nice site......i gotta learn to debug like you do I have no idea how you found the error so quickly Quote Link to comment Share on other sites More sharing options...
dmeeroff Posted January 18, 2010 Author Share Posted January 18, 2010 Thank you. Actually my boss wanted a change in format and when I tried to get it done, that's when I noticed it. Quote Link to comment Share on other sites More sharing options...
dmeeroff Posted January 18, 2010 Author Share Posted January 18, 2010 I've noticed another error on this page, maybe someone could give me a pointer. It says there are 127 records, 10 per page. When I get to page 10, it does not display any records. Is this a php coding issue? Diego Quote Link to comment Share on other sites More sharing options...
Buddski Posted January 18, 2010 Share Posted January 18, 2010 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 Quote Link to comment Share on other sites More sharing options...
dmeeroff Posted January 18, 2010 Author Share Posted January 18, 2010 If I take out the top search, then it will list all items from the database, we like to keep items in the database while also having them not show up during certain searches. Does this makes a difference? Diego Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.