Php Real Estate Script - Pagination

I am using a real estate script and have the listings displayed on the results page. Now I have a table with the details organized and I want to display the results in the table to their specific location on the table, and also I want to display 5 results per page, page numbers and next and previous pages as well as total records
The code is below - first is the php code that displays the information (used as a test) and below is the table where all needs to be placed!!!
<?php 
if(isset($_POST['search'])) { 
        foreach($_POST as $key=>$value) { 
                $$key = $value; 
        } 
        $query = mysql_query("SELECT * FROM listings WHERE price BETWEEN $minPrice AND $maxPrice AND listingType IN($listingType) AND region IN($region) AND propType IN($propType)") or die(mysql_error());        
        $numrows = mysql_num_rows($query); 
       ?>
	   
	   
	   <?php
	   if($numrows <= 0) { 
                echo 'No Results'; 
        } else { 
                while($row = mysql_fetch_array($query)) { 
                        echo 'Listing: '.$row['listingType'].', Region: '.$row['region'].', Property: '.$row['propType'].', Price: '.$row['price'].', Beds: '.$row['beds'].'<br />'; 
                } 
        } 
} 
?>
      
      <table width="100%" border="0">
        <tr>
          <td colspan="2"><div id="searchResults">
            <table width="100%" border="0">
              <tr>
                <td width="1%" rowspan="8">&nbsp;</td>
                <td height="17" colspan="4" class="style8"><?php echo $row['beds']; ?> bedroom <?php echo $row['propType']; ?> for <?php echo $row['listingType']; ?> in <?php echo $row['area']; ?>, <?php echo $row['region']; ?><br />
                  <br /></td>
              </tr>
              <tr>
                <td width="36%" rowspan="7"><div align="center"><?php echo '<img src=" images/' . $row['image1'] . '" />' . PHP_EOL;
 ?></div></td>
                <td class="style8"><strong>Ref: </strong></td>
                <td colspan="2" class="style8"><?php echo $row['refNum']; ?></td>
              </tr>
              <tr>
                <td class="style8"><strong>Location:</strong></td>
                <td colspan="2" class="style8"><?php echo $row['area']; ?>, <?php echo $row['region']; ?></td>
              </tr>
              <tr>
                <td class="style8"><strong>Type:</strong></td>
                <td colspan="2" class="style8"><?php echo $row['propType']; ?></td>
              </tr>
              <tr>
                <td class="style8"><strong>Price:</strong></td>
                <td colspan="2" class="style8">&euro;<?php echo $row['price']; ?></td>
              </tr>
              <tr>
                <td height="18" class="style8"><strong>Bedrooms:</strong></td>
                <td colspan="2" class="style8"><?php echo $row['beds']; ?></td>
              </tr>
              <tr>
                <td class="style8"><strong>Bathrooms:</strong></td>
                <td colspan="2" class="style8"><?php echo $row['baths']; ?></td>
              </tr>
              <tr>
                <td width="13%" height="31"><span class="style26"><a href="propdetails.php">View Details</a> <a onclick="Login_Modal_Window(0);" href="javascript:void(0);"></a></span></td>
                <td width="27%" class="style26"><a onclick="Login_Modal_Window(0);" href="javascript:void(0);">Save Listing</a></td>
                <td width="23%" class="style22">Posted by <?php echo $row['postedBy']; ?></td>
              </tr>
            </table>
          </div>
          <span class="style8"> Page 1 of 1</span> <br /></td>
        </tr>
       
       
      </table>

Open in new window

dino_angelidesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

john-formbyCommented:
Give me a few minutes and I will have a look :-)
0
dino_angelidesAuthor Commented:
ok john thank you :) take your time
0
john-formbyCommented:
Hi,

Please check the following code for searchresults.php.

Hope this helps,

John
searchresults.php
=================

<?php
$dbHost = "localhost";
$dbUser = "YOUR_USERNAME";
$dbPass = "YOUR_PASSWORD";
$dbName = "YOUR_DATABASE";
$db = mysql_connect($dbHost,$dbUser,$dbPass);
mysql_select_db($dbName,$db);

foreach($_REQUEST as $key=>$value) {  
    $$key = $value;  
}

$pall = $_REQUEST['p'];
if($pall != 'all') {
	$total_pages = $_REQUEST['p'];
	$per_page = 5;
	$cur_page = isset($_REQUEST['p']) ? (int)$_REQUEST['p'] : 1;
	$query = "SELECT * FROM listings WHERE price BETWEEN $minPrice AND $maxPrice AND listingType IN($listingType) AND region IN($region) AND propType IN($propType)";
	$result = @mysql_query($query);
	$numrows = mysql_num_rows($result);
	$total_pages = ceil($numrows / $per_page);
	if ($cur_page <1 || $cur_page> $total_pages) {
		$cur_page = 1;
	}
	$offset = (($cur_page - 1) * $per_page);
	$query = "SELECT * FROM listings WHERE price BETWEEN $minPrice AND $maxPrice AND listingType IN($listingType) AND region IN($region) AND propType IN($propType) LIMIT $offset, $per_page";
	$result = @mysql_query($query);
	$total = mysql_num_rows($result);
	$counter = 1 + (($cur_page-1)*$per_page);
} else {
	$query = "SELECT * FROM listings WHERE price BETWEEN $minPrice AND $maxPrice AND listingType IN($listingType) AND region IN($region) AND propType IN($propType)";
	$result = @mysql_query($query);
	$numrows = mysql_num_rows($result);
}

if($numrows <= 0) {  
    echo 'No Results';  
} else {  
    while($row = mysql_fetch_array($result)) {
    	
    ?>
        <table width="100%" border="0"> 
	        <tr> 
	          <td colspan="2"><div id="searchResults"> 
	            <table width="100%" border="0"> 
	              <tr> 
	                <td width="1%" rowspan="8">&nbsp;</td> 
	                <td height="17" colspan="4" class="style8"><?php echo $row['beds']; ?> bedroom <?php echo $row['propType']; ?> for <?php echo $row['listingType']; ?> in <?php echo $row['area']; ?>, <?php echo $row['region']; ?><br /> 
	                  <br /></td> 
	              </tr> 
	              <tr> 
	                <td width="36%" rowspan="7"><div align="center"><?php echo '<img src=" images/' . $row['image1'] . '" />' . PHP_EOL; 
	 ?></div></td> 
	                <td class="style8"><strong>Ref: </strong></td> 
	                <td colspan="2" class="style8"><?php echo $row['refNum']; ?></td> 
	              </tr> 
	              <tr> 
	                <td class="style8"><strong>Location:</strong></td> 
	                <td colspan="2" class="style8"><?php echo $row['area']; ?>, <?php echo $row['region']; ?></td> 
	              </tr> 
	              <tr> 
	                <td class="style8"><strong>Type:</strong></td> 
	                <td colspan="2" class="style8"><?php echo $row['propType']; ?></td> 
	              </tr> 
	              <tr> 
	                <td class="style8"><strong>Price:</strong></td> 
	                <td colspan="2" class="style8">&euro;<?php echo $row['price']; ?></td> 
	              </tr> 
	              <tr> 
	                <td height="18" class="style8"><strong>Bedrooms:</strong></td> 
	                <td colspan="2" class="style8"><?php echo $row['beds']; ?></td> 
	              </tr> 
	              <tr> 
	                <td class="style8"><strong>Bathrooms:</strong></td> 
	                <td colspan="2" class="style8"><?php echo $row['baths']; ?></td> 
	              </tr> 
	              <tr> 
	                <td width="13%" height="31"><span class="style26"><a href="propdetails.php">View Details</a> <a onclick="Login_Modal_Window(0);" href="javascript:void(0);"></a></span></td> 
	                <td width="27%" class="style26"><a onclick="Login_Modal_Window(0);" href="javascript:void(0);">Save Listing</a></td> 
	                <td width="23%" class="style22">Posted by <?php echo $row['postedBy']; ?></td> 
	              </tr> 
	            </table> 
	          </div> 
	          </td> 
	        </tr> 
	      </table> 
	<?php
    }
}
if($pall != 'all') {
	if($numrows > $per_page) {
		echo '<br />';
		$page_pad = 2;
		$min_page = max(1, $cur_page - $page_pad);
		$max_page = min($total_pages, $cur_page + $page_pad);
		$show_prev = $cur_page> 1 ? $cur_page - 1 : false;
		$show_next = $cur_page <$total_pages ? $cur_page + 1 : false;
	  	if ($show_prev) {
			echo "<a href=\"?p=1&amp;region=$region&amp;listingType=$listingType&amp;propType=$propType&amp;minPrice=$minPrice&amp;maxPrice=$maxPrice\">&laquo; First</a> ";
			echo "<a href=\"?p=$show_prev&amp;region=$region&amp;listingType=$listingType&amp;propType=$propType&amp;minPrice=$minPrice&amp;maxPrice=$maxPrice\">&lt; Prev</a> ";
		}
		for ($page = $min_page; $page <= $max_page; $page++) {
			if($cur_page<>$page)
				echo "<a href=\"?p=$page&amp;region=$region&amp;listingType=$listingType&amp;propType=$propType&amp;minPrice=$minPrice&amp;maxPrice=$maxPrice\">$page</a> ";
	   		else
	   			echo "$page ";
	   	}
	   	if ($show_next) {
	   		echo "<a href=\"?p=$show_next&amp;region=$region&amp;listingType=$listingType&amp;propType=$propType&amp;minPrice=$minPrice&amp;maxPrice=$maxPrice\">Next &gt;</a> ";
	   		echo "<a href=\"?p=$total_pages&amp;region=$region&amp;listingType=$listingType&amp;propType=$propType&amp;minPrice=$minPrice&amp;maxPrice=$maxPrice\">Last &raquo;</a>";
	   	}
		echo " &nbsp; <a href=\"?p=all&amp;region=$region&amp;listingType=$listingType&amp;propType=$propType&amp;minPrice=$minPrice&amp;maxPrice=$maxPrice\">View All</a><br />";
	}
}
?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

dino_angelidesAuthor Commented:
Perfect it works :) just one more thing
where do i put the styling?
lets say style26 is the css i want to add to the section below how do i do that?
echo "<a href=\"?p=$page&amp;region=$region&amp;listingType=$listingType&amp;propType=$propType&amp;minPrice=$minPrice&amp;maxPrice=$maxPrice\">$page</a> ";
0
john-formbyCommented:
Hi,

You can add it like this:

echo "<a class=\"style26\" href=\"?p=$page&amp;region=$region&amp;listingType=$listingType&amp;propType=$propType&amp;minPrice=$minPrice&amp;maxPrice=$maxPrice\">$page</a> ";

Hope this helps,

John
0
dino_angelidesAuthor Commented:
it worked...thx John,
if you are up to it i will put another question up for sorting the columns based on Price High-Low and Price Low-High
Thx again for answering that question too, much appreciated
0
john-formbyCommented:
You're welcome, glad it works for you.  Thanks for the points :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.