Jay2391 Posted September 17, 2006 Share Posted September 17, 2006 I have adatabase with some house listings I am trying to get 4 per page and my code looks okay but it seems to have an error som ewhere can some one look at it...<?php//// I know this is correct $row = array();$PicPart1 = "http://www.legacyrealtypros.com/ListPic/";$PicPart3 = "/Tum1.JPG";//// Connect to DB$dbh=mysql_connect ("localhost", "USER", "PASS") or die ('I cannot connect to the database because: ' . mysql_error());mysql_select_db ("User");////New codeif(!isset($_GET['page'])){ $page = 1; }else{ $page = $_GET['page']; }$max_results = 4;$from = (($page * $max_results) - $max_results);////Database tables$sql="select ListingID, Address, City, State, ZipCode, SchoolDist, Price, Rooms, Bathrooms, Sq_ft, Agent from Listings order by price";$rs = mysql_query( $sql, $dbh );while( $row = mysql_fetch_array( $rs )){ $i++; $ListingID = $row['ListingID']; $Address = $row['Address']; $City = $row['City'] ; $State = $row['State'] ; $ZipCode = $row['ZipCode']; $SchoolDist = $row['SchoolDist']; $Price = $row['Price']; $Rooms = $row['Rooms']; $Bathrooms = $row['Bathrooms']; $Sq_ft = $row['Sq_ft']; $Agent = $row['Agent']; $PicPart2 = $ListingID; $PicFinal = $PicPart1 . $PicPart2 . $PicPart3; $Display = "<img src=\"$PicFinal\"<br> "; echo "<a href=\"lrplist.php?ListingID=$ListingID\">$Display</a><br><br>"; echo ("Address: $Address<br>City: $City , $State<br> School District: $SchoolDist<br>"); echo ("Price: $Price<br> Rooms: $Rooms Bathrooms: $Bathrooms<br> Sqr FT: $Sq_ft"); echo ("<br> Agent: $Agent<br><br><br>");}$sql = mysql_query("SELECT * FROM pages LIMIT $from, $max_results");While ( $prow = mysql_fetch_array [$sql]){ }$total_results = mysql_results(mysql_query("SELECT COUNT (*) as Num FROM pages"), 0);$total_pages = ceil($total_results / $max_results);echo "<center>Select a Page <br />";if($page > 1){ $prev = ($page - 1); echo "<a href= "" . $_SERVER['PHP_SELF'] . "?page=$prev"><Previous</a>; for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "$i "; }else { echo "<a href= "". $_SERVER['PHP_SELF'] . "?page=$next">Next>></a>; }} ?> Quote Link to comment https://forums.phpfreaks.com/topic/21074-pagging/ Share on other sites More sharing options...
Wintergreen Posted September 17, 2006 Share Posted September 17, 2006 If you're getting an error, post it for us Quote Link to comment https://forums.phpfreaks.com/topic/21074-pagging/#findComment-93573 Share on other sites More sharing options...
sasa Posted September 17, 2006 Share Posted September 17, 2006 lines[code]if($page > 1){ $prev = ($page - 1); echo "<a href= "" . $_SERVER['PHP_SELF'] . "?page=$prev"><Previous[/url]; for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "$i "; }else { echo "<a href= "". $_SERVER['PHP_SELF'] . "?page=$next">Next>>[/url]; }}[/code]change to [code]if($page > 1){ $prev = ($page - 1); echo "<a href= \"" . $_SERVER['PHP_SELF'] . "?page=$prev><Previous </a>";} for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "$i "; }else { echo "<a href= \"".$_SERVER['PHP_SELF']."?page=$i\">| $i <a>"; }if($page<$total_pages){ $next = $page + 1; echo "<a href= \"". $_SERVER['PHP_SELF'] . "?page=$next\">| Next> <a>; }}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/21074-pagging/#findComment-93601 Share on other sites More sharing options...
Jay2391 Posted September 18, 2006 Author Share Posted September 18, 2006 Well i did the sujested changes and it didn't work...the only Syntax error i get is line 110 wich I am making a note about below... Check comments<?php//// I know this is correct $row = array();$PicPart1 = "http://www.legacyrealtypros.com/ListPic/";$PicPart3 = "/Tum1.JPG";//// Connect to DB This is correct$dbh=mysql_connect ("localhost", "USER", "PASS") or die ('I cannot connect to the database because: ' . mysql_error());mysql_select_db ("User");////New codeif(!isset($_GET['page'])){ $page = 1; }else{ $page = $_GET['page']; }$max_results = 4;$from = (($page * $max_results) - $max_results);////Database tables, this is correct$sql="select ListingID, Address, City, State, ZipCode, SchoolDist, Price, Rooms, Bathrooms, Sq_ft, Agent from Listings order by price";$rs = mysql_query( $sql, $dbh );while( $row = mysql_fetch_array( $rs )){ $i++; $ListingID = $row['ListingID']; $Address = $row['Address']; $City = $row['City'] ; $State = $row['State'] ; $ZipCode = $row['ZipCode']; $SchoolDist = $row['SchoolDist']; $Price = $row['Price']; $Rooms = $row['Rooms']; $Bathrooms = $row['Bathrooms']; $Sq_ft = $row['Sq_ft']; $Agent = $row['Agent']; $PicPart2 = $ListingID; $PicFinal = $PicPart1 . $PicPart2 . $PicPart3; $Display = "<img src=\"$PicFinal\" "; echo "<a href=\"lrplist.php?ListingID=$ListingID\">$Display[/url]"; echo ("Address: $AddressCity: $City , $State, School District: $SchoolDist"); echo ("Price: $Price , Rooms: $Rooms, Bathrooms: $Bathrooms, Sqr FT: $Sq_ft"); echo (" Agent: $Agent");}//// "Listings" is the name of the Table on the database, this is line 110$sql = mysql_query("SELECT * FROM Listings LIMIT $from, $max_results");While ( $prow = mysql_fetch_array [$sql]){ }$total_results = mysql_results(mysql_query("SELECT COUNT (*) as Num FROM pages"), 0);$total_pages = ceil($total_results / $max_results);echo "<center>Select a Page";/////New changes if($page > 1){ $prev = ($page - 1); echo "<a href= \"" . $_SERVER['PHP_SELF'] . "?page=$prev><Previous </a>";} for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "$i "; }else { echo "<a href= \"".$_SERVER['PHP_SELF']."?page=$i\">| $i <a>"; }if($page<$total_pages){ $next = $page + 1; echo "<a href= \"". $_SERVER['PHP_SELF'] . "?page=$next\">| Next> <a>; }} ?> Quote Link to comment https://forums.phpfreaks.com/topic/21074-pagging/#findComment-94000 Share on other sites More sharing options...
sasa Posted September 18, 2006 Share Posted September 18, 2006 try[code]<?php$row = array();$PicPart1 = "http://www.legacyrealtypros.com/ListPic/";$PicPart3 = "/Tum1.JPG";$dbh=mysql_connect ("localhost", "USER", "PASS")or die ('I cannot connect to the database because: ' . mysql_error());mysql_select_db ("User");if(!isset($_GET['page'])) $page = 1; else $page = $_GET['page'];$max_results = 4;$from = (($page * $max_results) - $max_results);$sql = mysql_query("SELECT * FROM Listings LIMIT $from, $max_results");While ($row = mysql_fetch_array($sql)){ $ListingID = $row['ListingID']; $Address = $row['Address']; $City = $row['City'] ; $State = $row['State'] ; $ZipCode = $row['ZipCode']; $SchoolDist = $row['SchoolDist']; $Price = $row['Price']; $Rooms = $row['Rooms']; $Bathrooms = $row['Bathrooms']; $Sq_ft = $row['Sq_ft']; $Agent = $row['Agent']; $PicPart2 = $ListingID; $PicFinal = $PicPart1 . $PicPart2 . $PicPart3; $Display = "<img src=\"$PicFinal\"> "; echo "<a href=\"lrplist.php?ListingID=$ListingID\">$Display</a>"; echo ("Address: $Address, $City , $State, School District: $SchoolDist"); echo ("Price: $Price , Rooms: $Rooms, Bathrooms: $Bathrooms, Sqr FT: $Sq_ft"); echo (" Agent: $Agent");}$total_results = mysql_results(mysql_query("SELECT COUNT (*) as Num FROM pages"), 0);$total_pages = ceil($total_results / $max_results);echo "<center>Select a Page";if($page > 1){ $prev = ($page - 1); echo "<a href= \"" . $_SERVER['PHP_SELF'] . "?page=$prev><Previous</a> ";}for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "| $i "; } else { echo "| <a href= \"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> "; }}if($page < $total_pages){ $next = $page + 1; echo "| <a href= \"". $_SERVER['PHP_SELF'] . "?page=$next\">Next></a>";} else echo '|';?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/21074-pagging/#findComment-94235 Share on other sites More sharing options...
Jay2391 Posted September 18, 2006 Author Share Posted September 18, 2006 Fatal error: Call to undefined function: mysql_results() in /home/jreina88/public_html/legacyrealtypros/list.php on line 113////This is line 113$total_results = mysql_results(mysql_query("SELECT COUNT (*) as Num FROM pages"), 0);I try chainging pages to Listings but that didn't work??? Quote Link to comment https://forums.phpfreaks.com/topic/21074-pagging/#findComment-94303 Share on other sites More sharing options...
Wintergreen Posted September 18, 2006 Share Posted September 18, 2006 mysql_result should work Quote Link to comment https://forums.phpfreaks.com/topic/21074-pagging/#findComment-94306 Share on other sites More sharing options...
Jay2391 Posted September 18, 2006 Author Share Posted September 18, 2006 is not working can you check if I am missing a capital letter or something ??? Quote Link to comment https://forums.phpfreaks.com/topic/21074-pagging/#findComment-94307 Share on other sites More sharing options...
Jay2391 Posted September 19, 2006 Author Share Posted September 19, 2006 it is mysql_resultnot mysql_resultsThanks!!!! ;D Quote Link to comment https://forums.phpfreaks.com/topic/21074-pagging/#findComment-94315 Share on other sites More sharing options...
Jay2391 Posted September 19, 2006 Author Share Posted September 19, 2006 Why Number Page # 1 ia acting as a prev button instead of page 1when you click any number that is not one it goes to that page but when you click one it goes to the prev page ???? Quote Link to comment https://forums.phpfreaks.com/topic/21074-pagging/#findComment-94320 Share on other sites More sharing options...
Jay2391 Posted September 19, 2006 Author Share Posted September 19, 2006 Soluction to my own questionif($page > 1){ $prev = ($page - 1); echo "<a href= \"" . $_SERVER['PHP_SELF'] . "?page=$prev\">Previous</a>"; Quote Link to comment https://forums.phpfreaks.com/topic/21074-pagging/#findComment-94325 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.