Jump to content


Photo

Pagging


  • Please log in to reply
10 replies to this topic

#1 Jay2391

Jay2391
  • Members
  • PipPipPip
  • Advanced Member
  • 167 posts
  • LocationMichigan

Posted 17 September 2006 - 05:22 PM

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.legacyrea....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 code
if(!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>;
}
}
             
 
?>


#2 Wintergreen

Wintergreen
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts

Posted 17 September 2006 - 05:27 PM

If you're getting an error, post it for us

#3 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 17 September 2006 - 06:11 PM

lines
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];
    }
}
change to
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>;
    }
}


#4 Jay2391

Jay2391
  • Members
  • PipPipPip
  • Advanced Member
  • 167 posts
  • LocationMichigan

Posted 18 September 2006 - 03:14 PM

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.legacyrea....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 code
if(!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>;
    }
}
             
 
?>


#5 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 18 September 2006 - 09:35 PM

try
<?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 '|';
?>


#6 Jay2391

Jay2391
  • Members
  • PipPipPip
  • Advanced Member
  • 167 posts
  • LocationMichigan

Posted 18 September 2006 - 11:39 PM

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???




#7 Wintergreen

Wintergreen
  • Members
  • PipPipPip
  • Advanced Member
  • 107 posts

Posted 18 September 2006 - 11:45 PM

mysql_result should work

#8 Jay2391

Jay2391
  • Members
  • PipPipPip
  • Advanced Member
  • 167 posts
  • LocationMichigan

Posted 18 September 2006 - 11:47 PM

is not working can you check if I am missing a capital letter or something ???

#9 Jay2391

Jay2391
  • Members
  • PipPipPip
  • Advanced Member
  • 167 posts
  • LocationMichigan

Posted 19 September 2006 - 12:04 AM

it is mysql_result

not mysql_results


Thanks!!!! ;D

#10 Jay2391

Jay2391
  • Members
  • PipPipPip
  • Advanced Member
  • 167 posts
  • LocationMichigan

Posted 19 September 2006 - 12:09 AM

Why Number Page # 1 ia acting as a prev button instead of page 1

when you click any number that is not one it goes to that page but when you click one it goes to the prev page ????

#11 Jay2391

Jay2391
  • Members
  • PipPipPip
  • Advanced Member
  • 167 posts
  • LocationMichigan

Posted 19 September 2006 - 12:26 AM

Soluction to my own question


if($page > 1){
    $prev = ($page - 1);
    echo "<a href=  \"" . $_SERVER['PHP_SELF'] . "?page=$prev\">Previous</a>";





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users