Jump to content

Pagging


Jay2391

Recommended Posts

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 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>;
}
}
             
 
?>
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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 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>;
    }
}
             
 
?>
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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


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.