This one is a baffler fer sure. Scenario:
I have this query (code below) that has the two main variables (category and loan_type) set by the search form. The search works fine and produces the results as long as both variables find a match. The problem is when the second variable has no match...then the script just fails. A blank page is all that is produced.
The two 'AND' statements represent those search requirements. If I purposefully search for an item that I know doesn't have results then the blank page appears. If I search for items known to be positive results then it works fine.
I also tried changing the 2nd 'AND' statement to 'OR' which then produced results without incident. However, the 'OR' is not the conditions we want as it produces results if either condition one OR condition two are met. But that experiment shows that the query works...just not when trying to meet both AND conditions when there's no matching results.
Search code (guts of it anyway):
Code:
// query for extracting lenders from amember database
$category = strip_tags(trim($_POST['category']));
$loantype = strip_tags(trim($_POST['loan_type']));
//$loanamount = strip_tags(trim($_POST['loan_size']));
$sql = "SELECT * FROM amember_members WHERE is_lender='Yes' AND '$category' IN (category_1, category_2, category_3, category_4, category_5) AND '$loantype' IN (loan_type, loan_type2, loan_type3, loan_type4, loan_type5) ORDER BY top_3 LIMIT 10";
$results = mysql_query($sql) or die(mysql_error());
$numrows = mysql_num_rows($results) or die(mysql_error());
if ($numrows === 0){
include 'header.php';
echo "<h3>No Results Found</h3><br>
<p class='bodytext'>No lenders matched your search criteria. Try modifying the search parameters for broader results.<br>\n";
echo "<br><input type=button value=\"Return to Search\" onClick=\"history.go(-1)\">";
include 'footer.php';
} else {
include 'header.php';
echo "<h3>The following lenders meet your search criteria.</h3><br>\n";
// create display of results in abbreviated format
while ($row = mysql_fetch_array($results)) {
echo "
<div class='wrapper_out' onmouseover=\"this.className='wrapper'\"; onmouseout=\"this.className='wrapper_out'\";>
<table width='500' border='0' align='center'>
<tr ><td colspan='2' class='lendertitle'>".$row['company_name']."</td></tr>
<tr><td colspan='2' class='lenderdesc'>Company phone: ".$row['company_phone']."</td></tr>
<tr><td width='300' class='lenderdesc'>Company contact: ".$row['company_contact']."</td>
<td width='200'><a class='lenderlink' href='loanrequest.php?lenderid=".$row['member_id']."'>Submit Loan Request</a></td></tr>
<tr><td colspan='2'>";
echo pullRating($row['member_id'],true,false,true);
echo "</td></tr>
</table></div><br />\n";
echo "<hr style='border-top: 1px dotted #666666' color='#666666' width='400' size='1'>";
}
include 'footer.php';
}
The 'if' statement checking results should divert to the 'No results found..' message if there's no matches. Instead it just results in a completely blank page which indicates the script is failing or not completing. Viewing page source shows nothing. So it's not outputting anything at all in the event there's no matches.
If you want to see this:
http://www.lenderfish.com/search-test.php
In first dropdown select anything. In 2nd one select anything BUT 'Stated' and you'll see results and that the search works. Go back to the search and then select 'Stated' in the 2nd box and try again. Blammo. Blank page. It fails to find a match because there aren't any members that match the 'Stated' loan type.
Ideas? Help?