• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 289
  • Last Modified:

Php Real Estate Script - Featured Listings

I have a real estate script and i would like to add featured listings option to it. What is the theory
a. Admin adds listings to the database. Along with all the other fields I want to add another field called featured. How do i define it in the database? fields and such......
So, whether the listing is featured or not the admin will check the checkbox defining the listing to be added as featured.
b. Now on my index page I have a link that goes to featuredproperties.php What do I need to do in order to view those featured listings?
0
dino_angelides
Asked:
dino_angelides
  • 11
  • 11
1 Solution
 
john-formbyCommented:
That sounds good.  A field called featured that is 0 as default and 1 if a featured property.  You can set this using the checkbox when you post the form as you have said.

You can just run a query to display the featured properties like:

$sql = mysql_query("SELECT * FROM listings WHERE featured = '1'") or die(mysql_error());

Hope this helps,

John
0
 
dino_angelidesAuthor Commented:
Hi John ...
So, in my database I set it up as enum ('0', '1') thats right?

Then the other concern is that, in my index page the link to the featured page its just an arrow that is clickable....so when the user clicks that it takes them to the featured page and thats where I add the code you gave me? along with the table we were working on yesterday right?
0
 
Avinash ZalaWeb ExpertCommented:
yes dino_angelides, its ok to use enum.

Addy
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
john-formbyCommented:
Yes, enum is fine for this.

Is your featured page only going to show the featured properties?  You can use the table I was looking at last night, you will just need to modify the queries because I am guessing this is not the result of a search?
0
 
dino_angelidesAuthor Commented:
Yes it only shows featured properties, i have modified the query we were working on last night but it does not work.....i am attaching the code so you can take a look at it!!! The featured page I want it to show all that the searchresult page is showing including the sorting, 5 results per page etc....
<div id="mainContent">
    <div id="header1"><img src="/RealEstateOnline/images/FeaturedPropertiesHeader.jpg" width="1009" height="58" /></div>
    <div id="centerContent">
      <?
  
foreach($_REQUEST as $key=>$value) {  
    $$key = $value;  
}

$pall = $_REQUEST['p'];
$sort = $_REQUEST['sort'];
if(!isset($_REQUEST['sort'])) {
	$sort = '1';
}
//echo $sort;
echo '
<form id="searchResultsForm" name="searchResultsForm" method="post" action="searchresults.php">
	<input type="hidden" name="region" value="'.$region.'" />
	<input type="hidden" name="listingType" value="'.$listingType.'" />
	<input type="hidden" name="propType" value="'.$propType.'" />
	<input type="hidden" name="minPrice" value="'.$minPrice.'" />
	<input type="hidden" name="maxPrice" value="'.$maxPrice.'" />
    <table width="100%" border="0">
        <tr>
        	<td width="65%" height="31">&nbsp;</td>
            
            <td width="17%">
				<select name="sort" class="style21" id="sort">
                    <option value="1" '.($sort=="1" ? 'selected' : '').'>Price High-Low</option>
                    <option value="2" '.($sort=="2" ? 'selected' : '').'>Price Low-High</option>
                 	</select>
            	<input type="submit" name="submit" value="Sort" />
			</td>
        </tr>
    </table> 
</form>';


if($pall != 'all') {
	$total_pages = $_REQUEST['p'];
	$per_page = 5;
	$cur_page = isset($_REQUEST['p']) ? (int)$_REQUEST['p'] : 1;
	if($sort == '2') {
		$query = "SELECT * FROM listings WHERE featured = '1' ORDER BY price ASC";
	} elseif($sort == '1') {
		$query = "SELECT * FROM listings WHERE featured = '1' ORDER BY price DESC";
	}
	$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);
	if($sort == '2') {
		$query = "SELECT * FROM listings WHERE featured = '1' ORDER BY price ASC $offset, $per_page";
	} elseif($sort == '1') {
		$query = "SELECT * FROM listings WHERE featured = '1' ORDER BY price DESC LIMIT $offset, $per_page";
	}
	$result = @mysql_query($query);
	$total = mysql_num_rows($result);
	$counter = 1 + (($cur_page-1)*$per_page);
} else {
	if($sort == '2') {
		$query = "SELECT * FROM listings WHERE featured = '1' ORDER BY price ASC";
	} elseif($sort == '1') {
		$query = "SELECT * FROM listings WHERE featured = '1' ORDER BY price DESC";
	}
	$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="style261"><a href="propdetails.php">View Details</a> <a onclick="Login_Modal_Window(0);" href="javascript:void(0);"></a></span></td>
                <td width="27%" class="style261"><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 class=\"style26\" href=\"?p=1&amp;region=$region&amp;listingType=$listingType&amp;propType=$propType&amp;minPrice=$minPrice&amp;maxPrice=$maxPrice&amp;sort=$sort\">&laquo; First</a> ";
			echo "<a class=\"style26\" href=\"?p=$show_prev&amp;region=$region&amp;listingType=$listingType&amp;propType=$propType&amp;minPrice=$minPrice&amp;maxPrice=$maxPrice&amp;sort=$sort\">&lt; Prev</a> ";
		}
		for ($page = $min_page; $page <= $max_page; $page++) {
			if($cur_page<>$page)
				echo "<a class=\"style26\" href=\"?p=$page&amp;region=$region&amp;listingType=$listingType&amp;propType=$propType&amp;minPrice=$minPrice&amp;maxPrice=$maxPrice&amp;sort=$sort\">$page</a> ";
	   		else
	   			echo "<span class=\"style26\">$page </span>";
	   	}
	   	if ($show_next) {
	   		echo "<a class=\"style26\" href=\"?p=$show_next&amp;region=$region&amp;listingType=$listingType&amp;propType=$propType&amp;minPrice=$minPrice&amp;maxPrice=$maxPrice&amp;sort=$sort\">Next &gt;</a> ";
	   		echo "<a class=\"style26\" href=\"?p=$total_pages&amp;region=$region&amp;listingType=$listingType&amp;propType=$propType&amp;minPrice=$minPrice&amp;maxPrice=$maxPrice&amp;sort=$sort\">Last &raquo;</a>";
	   	}
		//echo " &nbsp; <a class=\"style26\" href=\"?p=all&amp;region=$region&amp;listingType=$listingType&amp;propType=$propType&amp;minPrice=$minPrice&amp;maxPrice=$maxPrice&amp;sort=$sort\">View All</a><br />";
	}
}
?>

Open in new window

0
 
john-formbyCommented:
You have commented out the View All code.  Do you want this for this page or would you like me to remove it?
0
 
dino_angelidesAuthor Commented:
well, this is the code as i got it from the searchresults.....anyhow do it however u think its correct and I will see what I need to comment later :)
0
 
john-formbyCommented:
What is your page called?  Is it featured.php?
0
 
john-formbyCommented:
Hi,

I have guessed your page is called featured.php.  If it is not, please change this line:

<form id="searchResultsForm" name="searchResultsForm" method="post" action="featured.php">

Hope this helps,

John
<div id="mainContent"> 
    <div id="header1"><img src="/RealEstateOnline/images/FeaturedPropertiesHeader.jpg" width="1009" height="58" /></div> 
    <div id="centerContent"> 
      <?php 

foreach($_REQUEST as $key=>$value) {   
    $$key = $value;   
} 
 
$pall = $_REQUEST['p']; 
$sort = $_REQUEST['sort']; 
if(!isset($_REQUEST['sort'])) { 
        $sort = '1'; 
}

echo $sort;

echo ' 
<form id="searchResultsForm" name="searchResultsForm" method="post" action="featured.php"> 
    <table width="100%" border="0"> 
        <tr> 
                <td width="65%" height="31">&nbsp;</td> 
             
            <td width="17%"> 
                                <select name="sort" class="style21" id="sort"> 
                    <option value="1" '.($sort=="1" ? 'selected' : '').'>Price High-Low</option> 
                    <option value="2" '.($sort=="2" ? 'selected' : '').'>Price Low-High</option> 
                        </select> 
                <input type="submit" name="submit" value="Sort" /> 
                        </td> 
        </tr> 
    </table>  
</form>'; 
 
 
if($pall != 'all') { 
        $total_pages = $_REQUEST['p']; 
        $per_page = 1; 
        $cur_page = isset($_REQUEST['p']) ? (int)$_REQUEST['p'] : 1; 
        if($sort == '2') { 
            $query = "SELECT * FROM listings WHERE featured = '1' ORDER BY price ASC"; 
        } elseif($sort == '1') { 
            $query = "SELECT * FROM listings WHERE featured = '1' ORDER BY price DESC"; 
        } 
        $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); 
        if($sort == '2') { 
            $query = "SELECT * FROM listings WHERE featured = '1' ORDER BY price ASC LIMIT $offset, $per_page"; 
        } elseif($sort == '1') { 
            $query = "SELECT * FROM listings WHERE featured = '1' ORDER BY price DESC LIMIT $offset, $per_page"; 
        } 
        $result = @mysql_query($query); 
        $total = mysql_num_rows($result); 
        $counter = 1 + (($cur_page-1)*$per_page); 
} else { 
        if($sort == '2') { 
            $query = "SELECT * FROM listings WHERE featured = '1' ORDER BY price ASC"; 
        } elseif($sort == '1') { 
            $query = "SELECT * FROM listings WHERE featured = '1' ORDER BY price DESC"; 
        } 
        $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="style261"><a href="propdetails.php">View Details</a> <a onclick="Login_Modal_Window(0);" href="javascript:void(0);"></a></span></td> 
                <td width="27%" class="style261"><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 class=\"style26\" href=\"?p=1&amp;sort=$sort\">&laquo; First</a> "; 
                        echo "<a class=\"style26\" href=\"?p=$show_prev&amp;sort=$sort\">&lt; Prev</a> "; 
                } 
                for ($page = $min_page; $page <= $max_page; $page++) { 
                        if($cur_page<>$page) 
                                echo "<a class=\"style26\" href=\"?p=$page&amp;sort=$sort\">$page</a> "; 
                        else 
                                echo "<span class=\"style26\">$page </span>"; 
                } 
                if ($show_next) { 
                        echo "<a class=\"style26\" href=\"?p=$show_next&amp;sort=$sort\">Next &gt;</a> "; 
                        echo "<a class=\"style26\" href=\"?p=$total_pages&amp;sort=$sort\">Last &raquo;</a>"; 
                } 
                echo " &nbsp; <a class=\"style26\" href=\"?p=all&amp;sort=$sort\">View All</a><br />"; 
        } 
} 
?>

Open in new window

0
 
dino_angelidesAuthor Commented:
it gives me an error to this section
$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;

error
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in .........
0
 
john-formbyCommented:
Not for me.  Please can you post your full page code?
0
 
dino_angelidesAuthor Commented:
There you go
<?
  
foreach($_REQUEST as $key=>$value) {  
    $$key = $value;  
}

$pall = $_REQUEST['p'];
$sort = $_REQUEST['sort'];
if(!isset($_REQUEST['sort'])) {
	$sort = '1';
}
//echo $sort;
echo '
<form id="featuredPropertiesForm" name="featuredPropertiesForm" method="post" action="featuredproperties.php">
	<input type="hidden" name="region" value="'.$region.'" />
	<input type="hidden" name="listingType" value="'.$listingType.'" />
	<input type="hidden" name="propType" value="'.$propType.'" />
	<input type="hidden" name="minPrice" value="'.$minPrice.'" />
	<input type="hidden" name="maxPrice" value="'.$maxPrice.'" />
    <table width="100%" border="0">
        <tr>
        	<td width="65%" height="31">&nbsp;</td>
            
            <td width="17%">
				<select name="sort" class="style21" id="sort">
                    <option value="1" '.($sort=="1" ? 'selected' : '').'>Price High-Low</option>
                    <option value="2" '.($sort=="2" ? 'selected' : '').'>Price Low-High</option>
                 	</select>
            	<input type="submit" name="submit" value="Sort" />
			</td>
        </tr>
    </table> 
</form>';


if($pall != 'all') {
	$total_pages = $_REQUEST['p'];
	$per_page = 5;
	$cur_page = isset($_REQUEST['p']) ? (int)$_REQUEST['p'] : 1;
	if($sort == '2') {
		$query = "SELECT * FROM listings WHERE featured = 'Yes' ORDER BY price ASC";
	} elseif($sort == '1') {
		$query = "SELECT * FROM listings WHERE featured = 'Yes' ORDER BY price DESC";
	}
	$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);
	if($sort == '2') {
		$query = "SELECT * FROM listings WHERE featured = 'Yes' ORDER BY price ASC $offset, $per_page";
	} elseif($sort == '1') {
		$query = "SELECT * FROM listings WHERE featured = 'Yes' ORDER BY price DESC LIMIT $offset, $per_page";
	}
	$result = @mysql_query($query);
	$total = mysql_num_rows($result);
	$counter = 1 + (($cur_page-1)*$per_page);
} else {
	if($sort == '2') {
		$query = "SELECT * FROM listings WHERE featured = 'Yes' ORDER BY price ASC";
	} elseif($sort == '1') {
		$query = "SELECT * FROM listings WHERE featured = 'Yes' ORDER BY price DESC";
	}
	$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="style261"><a href="propdetails.php">View Details</a> <a onclick="Login_Modal_Window(0);" href="javascript:void(0);"></a></span></td>
                <td width="27%" class="style261"><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 class=\"style26\" href=\"?p=1&amp;region=$region&amp;listingType=$listingType&amp;propType=$propType&amp;minPrice=$minPrice&amp;maxPrice=$maxPrice&amp;sort=$sort\">&laquo; First</a> ";
			echo "<a class=\"style26\" href=\"?p=$show_prev&amp;region=$region&amp;listingType=$listingType&amp;propType=$propType&amp;minPrice=$minPrice&amp;maxPrice=$maxPrice&amp;sort=$sort\">&lt; Prev</a> ";
		}
		for ($page = $min_page; $page <= $max_page; $page++) {
			if($cur_page<>$page)
				echo "<a class=\"style26\" href=\"?p=$page&amp;region=$region&amp;listingType=$listingType&amp;propType=$propType&amp;minPrice=$minPrice&amp;maxPrice=$maxPrice&amp;sort=$sort\">$page</a> ";
	   		else
	   			echo "<span class=\"style26\">$page </span>";
	   	}
	   	if ($show_next) {
	   		echo "<a class=\"style26\" href=\"?p=$show_next&amp;region=$region&amp;listingType=$listingType&amp;propType=$propType&amp;minPrice=$minPrice&amp;maxPrice=$maxPrice&amp;sort=$sort\">Next &gt;</a> ";
	   		echo "<a class=\"style26\" href=\"?p=$total_pages&amp;region=$region&amp;listingType=$listingType&amp;propType=$propType&amp;minPrice=$minPrice&amp;maxPrice=$maxPrice&amp;sort=$sort\">Last &raquo;</a>";
	   	}
		//echo " &nbsp; <a class=\"style26\" href=\"?p=all&amp;region=$region&amp;listingType=$listingType&amp;propType=$propType&amp;minPrice=$minPrice&amp;maxPrice=$maxPrice&amp;sort=$sort\">View All</a><br />";
	}
}
?>

Open in new window

0
 
john-formbyCommented:
You have just posted the old code, not the one I posted?
0
 
dino_angelidesAuthor Commented:
well, now i posted yours and the only thing I changed is the  part where it says WHERE featured = 'Yes' you had 1 i changed it to yes
still does not work and its very weird
if($pall != 'all') { 
        $total_pages = $_REQUEST['p']; 
        $per_page = 1; 
        $cur_page = isset($_REQUEST['p']) ? (int)$_REQUEST['p'] : 1; 
        if($sort == '2') { 
            $query = "SELECT * FROM listings WHERE featured = 'Yes' ORDER BY price ASC"; 
        } elseif($sort == '1') { 
            $query = "SELECT * FROM listings WHERE featured = 'Yes' ORDER BY price DESC"; 
        } 
        $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); 
        if($sort == '2') { 
            $query = "SELECT * FROM listings WHERE featured = 'Yes' ORDER BY price ASC LIMIT $offset, $per_page"; 
        } elseif($sort == '1') { 
            $query = "SELECT * FROM listings WHERE featured = 'Yes' ORDER BY price DESC LIMIT $offset, $per_page"; 
        } 
        $result = @mysql_query($query); 
        $total = mysql_num_rows($result); 
        $counter = 1 + (($cur_page-1)*$per_page); 
} else { 
        if($sort == '2') { 
            $query = "SELECT * FROM listings WHERE featured = 'Yes' ORDER BY price ASC"; 
        } elseif($sort == '1') { 
            $query = "SELECT * FROM listings WHERE featured = 'Yes' ORDER BY price DESC"; 
        } 
        $result = @mysql_query($query); 
        $numrows = mysql_num_rows($result);

Open in new window

0
 
john-formbyCommented:
I thought you were using enum with a value of 0 or 1?

If you do have Yes in your table, then I can't see any problem with the code.

Can you post the full page?
0
 
dino_angelidesAuthor Commented:
let me do enum values of 1 and 0 and see what happens
0
 
dino_angelidesAuthor Commented:
Thats the code, I changed the database to values 0 and 1 and still get the error for the mysql_num_rows(): and also it says No Results
<div id="mainContent"> 
    <div id="header1"><img src="/RealEstateOnline/images/FeaturedPropertiesHeader.jpg" width="1009" height="58" /></div> 
    <div id="centerContent"> 
      <?php 

foreach($_REQUEST as $key=>$value) {   
    $$key = $value;   
} 
 
$pall = $_REQUEST['p']; 
$sort = $_REQUEST['sort']; 
if(!isset($_REQUEST['sort'])) { 
        $sort = '1'; 
}

echo $sort;

echo ' 
<form id="searchResultsForm" name="searchResultsForm" method="post" action="featuredproperties.php"> 
    <table width="100%" border="0"> 
        <tr> 
                <td width="65%" height="31">&nbsp;</td> 
             
            <td width="17%"> 
                                <select name="sort" class="style21" id="sort"> 
                    <option value="1" '.($sort=="1" ? 'selected' : '').'>Price High-Low</option> 
                    <option value="2" '.($sort=="2" ? 'selected' : '').'>Price Low-High</option> 
                        </select> 
                <input type="submit" name="submit" value="Sort" /> 
                        </td> 
        </tr> 
    </table>  
</form>'; 
 
 
if($pall != 'all') { 
        $total_pages = $_REQUEST['p']; 
        $per_page = 1; 
        $cur_page = isset($_REQUEST['p']) ? (int)$_REQUEST['p'] : 1; 
        if($sort == '2') { 
            $query = "SELECT * FROM listings WHERE featured = '1' ORDER BY price ASC"; 
        } elseif($sort == '1') { 
            $query = "SELECT * FROM listings WHERE featured = '1' ORDER BY price DESC"; 
        } 
        $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); 
        if($sort == '2') { 
            $query = "SELECT * FROM listings WHERE featured = '1' ORDER BY price ASC LIMIT $offset, $per_page"; 
        } elseif($sort == '1') { 
            $query = "SELECT * FROM listings WHERE featured = '1' ORDER BY price DESC LIMIT $offset, $per_page"; 
        } 
        $result = @mysql_query($query); 
        $total = mysql_num_rows($result); 
        $counter = 1 + (($cur_page-1)*$per_page); 
} else { 
        if($sort == '2') { 
            $query = "SELECT * FROM listings WHERE featured = '1' ORDER BY price ASC"; 
        } elseif($sort == '1') { 
            $query = "SELECT * FROM listings WHERE featured = '1' ORDER BY price DESC"; 
        } 
        $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="style261"><a href="propdetails.php">View Details</a> <a onclick="Login_Modal_Window(0);" href="javascript:void(0);"></a></span></td> 
                <td width="27%" class="style261"><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 class=\"style26\" href=\"?p=1&amp;sort=$sort\">&laquo; First</a> "; 
                        echo "<a class=\"style26\" href=\"?p=$show_prev&amp;sort=$sort\">&lt; Prev</a> "; 
                } 
                for ($page = $min_page; $page <= $max_page; $page++) { 
                        if($cur_page<>$page) 
                                echo "<a class=\"style26\" href=\"?p=$page&amp;sort=$sort\">$page</a> "; 
                        else 
                                echo "<span class=\"style26\">$page </span>"; 
                } 
                if ($show_next) { 
                        echo "<a class=\"style26\" href=\"?p=$show_next&amp;sort=$sort\">Next &gt;</a> "; 
                        echo "<a class=\"style26\" href=\"?p=$total_pages&amp;sort=$sort\">Last &raquo;</a>"; 
                } 
                echo " &nbsp; <a class=\"style26\" href=\"?p=all&amp;sort=$sort\">View All</a><br />"; 
        } 
} 
?>

Open in new window

0
 
john-formbyCommented:
You are not connecting to the database.

You are missing something like this:

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

Hope this helps,

John
0
 
dino_angelidesAuthor Commented:
seriously something is wrong with my copy pasting...i was sure it was there...anyhow it works now but I have only 1 result per page....where would the problem be? i replaced the code with the one from yesterday but still nothing...the results are shown as they should but 1 per page
0
 
dino_angelidesAuthor Commented:
ok got it i found it sorry !!!I :)
I will post another question in a bit!!! hope you are up to it....at least i am catching up a bit!!! :) thank you again for solving this!!!!
0
 
john-formbyCommented:
No problem :-)  I am going out for a little while but will look out for your question when I get back :-)
0
 
john-formbyCommented:
Ah, the 1 record per page is because of this line:

$per_page = 1;

Change 1 to 5.

I use 1 because I don't have much data to test with :-)
0
 
dino_angelidesAuthor Commented:
ok john thank you !!!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 11
  • 11
Tackle projects and never again get stuck behind a technical roadblock.
Join Now