Jump to content

[SOLVED] else statement not working


simcoweb

Recommended Posts

Ken2k7... me either...lol! This one is a stumper. If the query fails it should meet the condition of the if/else and display the else content.

 

Regarding your question, actually you can't select just one. The javascript validation prohibits the first item listed from being a selection (thanks to the javascript forum guys). It requires two selections to make it work.

 

Gentlemen, I have to get some sleep. Gotta get up in less than 5 hours. Perhaps my rested eyes can spot the problem tomorrow. Thanks again for your posts. Let's tackle it in the morning!

Link to comment
Share on other sites

Ken2k7... it's a new day. I'll single quote 'em and give it a try again to get things started on the quest to solvation.. !

 

 

Kensk7, just wanted to report back, adding the single quotes actually broke the script. It returned...what else...a blank page! So I went back to the non-single quote setup.

 

Still breaking, though, when searching for non-available data. Working on that.

 

Ok, more info. I changed the second 'AND' condition (which is the loan_type) to an 'OR' and that works. Of course, it doesn't provide the accuracy of the 'AND' search that I need. But, at least it narrows possibly what the problem is. The second 'AND' condition is breaking when there's no matches.

Link to comment
Share on other sites

Ok, new update. I had someone look at this issue and what they had me do is remove the two 'or die(mysql_error()); ' statements associated with the $numrows and $results from the query. Once I did that the search worked perfectly. It displays the 'No results...' message when there are none (instead of just a blank page) and the results when there are matches.

 

In explaining it, the 'or die' was causing the script to 'die' without producing an error message on the next page (since it was looking for a mysql_error). Therefore the blank page.

 

In any event, i'd still like to know what was occurring for future edification and why it would 'die' at that spot.

 

Just for reference, here's the final code used:

 

if (isset($_POST['search'])) {
// 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);
$numrows = mysql_num_rows($results);

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';
}
}

Link to comment
Share on other sites

Final note on this. It was just the 'or die(mysql_error())' function assigned to the $numrows statement. Once that was removed everything worked perfectly. The explanation for anyone's edification:

 

When mysql_num_rows() returns a zero(false) the or die() is evaluated. Since there is no mysql_error() (which is set by the query, not any of the mysql_fetch_xxxx() or mysql_num_rows() function calls) nothing is displayed.

 

Again, thank all of you for your help. It turns out it was something that simple! Another lesson learned :)

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.