simcoweb Posted January 4, 2008 Share Posted January 4, 2008 I'm running this query whereas IF there's no results then it should display an alternative message. However, when there's no results it just shows a blank page entirely...which means it's breaking somewhere but I can't see why it's not functioning properly. If I select in the search the two elements that I know produce results then it displays fine. It's only when there's no results that it breaks. // 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(empty($results )){ 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 { Quote Link to comment Share on other sites More sharing options...
redarrow Posted January 4, 2008 Share Posted January 4, 2008 <?php if(mysql_num_rows($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 { Quote Link to comment Share on other sites More sharing options...
awpti Posted January 4, 2008 Share Posted January 4, 2008 $results will only end up being a resource identifier. This does not eval as empty since it has a "value". You'll want to make use of mysql_num_rows($result) ( returns the number of rows found by that resource ID ). if((mysql_num_rows($results) === 0 )) { // empty. } else { // not empty! } Quote Link to comment Share on other sites More sharing options...
simcoweb Posted January 4, 2008 Author Share Posted January 4, 2008 Hmmm... still producing a blank page. I've tried SOOO many combos and methods. Right now here's what I have: $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 (mysql_num_rows($results) === 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 { If you go to: http://www.lenderfish.com/search-test.php select 'Stated' in the first drop down and anything in the next and you'll see what happens. Might help. Basically there are no results from the database for anything in the query related to Stated so it should produce the IF condition if that's the case. But it's not. Quote Link to comment Share on other sites More sharing options...
redarrow Posted January 4, 2008 Share Posted January 4, 2008 post the whole page pleae cheers.................. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted January 4, 2008 Share Posted January 4, 2008 How are your database tables set up? Quote Link to comment Share on other sites More sharing options...
redarrow Posted January 4, 2008 Share Posted January 4, 2008 try that $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 (!$results){ 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 { Quote Link to comment Share on other sites More sharing options...
simcoweb Posted January 4, 2008 Author Share Posted January 4, 2008 Here's the whole setup: <?php ini_set("display_errors", 1); error_reporting(E_ALL); ini_set("display_startup_errors", 1); include 'db_config.php'; /** * @author rockmetal * @copyright 2007 */ // 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 (mysql_num_rows($results) === 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'; } ?> redarrow, I did try that if(!$results) { method and got the same thing. That's what's puzzling. Ken2k7, the tables are set up fine. If you search for something you know is there then the results display perfectly. It's only when one of the conditions isn't met. In this case, as in the example I gave, if you choose Stated then whatever in the second drop down then the query should be empty and the IF condition should be met and HTML displayed. Not doing that. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted January 4, 2008 Share Posted January 4, 2008 I didn't ask if the tables were set up correctly or not. I was asking to see how the data is stored. Do you have a separate column that have data for each value of the dropdown? Something like: table: dropdown1 | dropdown 2 ----------------------------------- convensional | purchase . | . . | . . | . or something else? I'm only questioning about the category_1, category_2 etc in your query. Quote Link to comment Share on other sites More sharing options...
redarrow Posted January 4, 2008 Share Posted January 4, 2008 give this ago only a stab in the dark ok <?php ini_set("display_errors", 1); error_reporting(E_ALL); ini_set("display_startup_errors", 1); include 'db_config.php'; /** * @author rockmetal * @copyright 2007 */ // 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()); if(mysql_num_rows($results) > 0){ while($numrows = mysql_fetch_assoc($results)){ include 'header.php'; echo "<h3>The following lenders meet your search criteria.</h3><br>\n"; // create display of results in abbreviated format 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'; }else{ 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'; } } ?> Quote Link to comment Share on other sites More sharing options...
simcoweb Posted January 4, 2008 Author Share Posted January 4, 2008 Ken2K7, basically they're set up like your example. Two separate tables containing the items as shown in those dropdowns respectively. The two drop downs are populating perfectly with the selections. redarrow, tried it and still produces a blank page when using the 'fail' search. Also, produces a slew of errors such as: Notice: Undefined variable: row in /home2/wwwfish/public_html/search.php on line 35 Notice: Undefined variable: row in /home2/wwwfish/public_html/search.php on line 36 Notice: Undefined variable: row in /home2/wwwfish/public_html/search.php on line 37 Notice: Undefined variable: row in /home2/wwwfish/public_html/search.php on line 38 Company phone: Company contact: Submit Loan Request Notice: Undefined variable: row in /home2/wwwfish/public_html/search.php on line 41 Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted January 4, 2008 Share Posted January 4, 2008 Then why not try this query: <?php $sql = mysql_query("SELECT * FROM table_name WHERE category1='$category' AND category2='$loantype'"); if (!$sql || (mysql_num_rows($sql) < 1)){ // display error msg } else { // something else } ?> Quote Link to comment Share on other sites More sharing options...
simcoweb Posted January 4, 2008 Author Share Posted January 4, 2008 Well, perhaps I should explain. The dropdowns are populated from separate tables that are totally separate from the data for the results. The $category and $loantype variables are populated by the form that holds the two dropdowns. The data containing the content for the results is in a table called 'amember_members' as it's looking through the member's data to see what matches. Now, the data is much more complex. There's not a single 'category' field. There's 5. (category_1, _2, etc.) and there's 5 different loan_type fields (_1, _2,_3,_4, _5). So, the idea is to match their two selections from the dropdown with the various fields in the data. When it's done it should display the results. If there aren't any that match the criteria then it should display the 'else' content. Unfortunately it's not. Quote Link to comment Share on other sites More sharing options...
redarrow Posted January 4, 2008 Share Posted January 4, 2008 try this please cheers.... <?php ini_set("display_errors", 1); error_reporting(E_ALL); ini_set("display_startup_errors", 1); include ('db_config.php'); /** * @author rockmetal * @copyright 2007 */ // 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()); while($numrows=mysql_fetch_assoc($results)){ if(mysql_num_rows($results)==1){ include ('header.php'); echo "<h3>The following lenders meet your search criteria.</h3><br>"; // create display of results in abbreviated format 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> <hr style='border-top: 1px dotted #666666' color='#666666' width='400' size='1'>"; include('footer.php'); }else{ 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> <br><input type=button value='Return to Search' onClick='history.go(-1)'>"; include ('footer.php'); } } ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted January 4, 2008 Share Posted January 4, 2008 this better work lol going mad here <?php ini_set("display_errors", 1); error_reporting(E_ALL); ini_set("display_startup_errors", 1); include ('db_config.php'); /** * @author rockmetal * @copyright 2007 */ // 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()); if(mysql_num_rows($results)==1){ $row=mysql_fetch_assoc($results); include ('header.php'); echo "<h3>The following lenders meet your search criteria.</h3><br>"; // create display of results in abbreviated format 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> <hr style='border-top: 1px dotted #666666' color='#666666' width='400' size='1'>"; include('footer.php'); }else{ 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> <br><input type=button value='Return to Search' onClick='history.go(-1)'>"; include ('footer.php'); } ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted January 4, 2008 Share Posted January 4, 2008 PRINT_R(); QUERY Quote Link to comment Share on other sites More sharing options...
simcoweb Posted January 4, 2008 Author Share Posted January 4, 2008 I'll try it..but wouldn't the absence of the 'while' loop limit me to one result? There would most likely be up to 10 lenders that would match the criteria for each category. Let me give this a shot. Be right back. Ok, gave it a whirl. Now, no matter what I select, it displays the 'No results match...' content. So, what's happening with this version is no results are being pulled. Quote Link to comment Share on other sites More sharing options...
redarrow Posted January 4, 2008 Share Posted January 4, 2008 come on one off you must no please help i am tring my best here..... Quote Link to comment Share on other sites More sharing options...
redarrow Posted January 4, 2008 Share Posted January 4, 2008 try this do we see anythink <?php ini_set("display_errors", 1); error_reporting(E_ALL); ini_set("display_startup_errors", 1); include ('db_config.php'); /** * @author rockmetal * @copyright 2007 */ // 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()); while($row=mysql_fetch_assoc($results)){ include ('header.php'); echo "<h3>The following lenders meet your search criteria.</h3><br>"; // create display of results in abbreviated format 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> <hr style='border-top: 1px dotted #666666' color='#666666' width='400' size='1'>"; include('footer.php'); } ?> Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted January 4, 2008 Share Posted January 4, 2008 Put single quotes around the category_1, _2 etc..and for the loan ones too. If that don't work, can you show me your database structure and its tables. I'm still not really understanding on how they're set up. Quote Link to comment Share on other sites More sharing options...
awpti Posted January 4, 2008 Share Posted January 4, 2008 <?php include 'db_config.php'; /** * @author rockmetal * @copyright 2007 */ // 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()); if(mysql_num_rows($results) >= 1) // See the problem here? You're expecting more than one. The logic provided in the previous one only matched if there was -1- result. { include 'header.php'; echo "<h3>The following lenders meet your search criteria.</h3><br>"; while($row = mysql_fetch_assoc($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><hr style='border-top: 1px dotted #666666' color='#666666' width='400' size='1'>"; } include 'footer.php'; } else { 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> <br><input type=button value='Return to Search' onClick='history.go(-1)'>"; include 'footer.php'; } ?> I don't understand why people are continuing without a loop. He expects >1 result, so always loop. I cleaned up the code a bit since it was a bit of a mess. You may need to adjust the output of the echo in the loop. Quote Link to comment Share on other sites More sharing options...
simcoweb Posted January 4, 2008 Author Share Posted January 4, 2008 lol... dude, BELIEVE ME.. i'm totally appreciative of your help. Now, just tried the latest version. STILL fails when one of the search criteria isn't met. I've been scratching my head on this till it bleeds. Ok, more info: What i'm doing is omitting the 'Stated' loan_type from a member's profile. Then, i'm searching for that loan type in the 2nd drop down along with a category in the first drop down that I know is listed in his profile. IF I select both criteria knowing full well that they ARE in his profile then the results display fine. SO...the way the query is written is 'AND' this 'AND' that so that it should meet both requirements in order to display in the results. IF both conditions aren't met (along with the 'is_lender' condition which specifies that their membership status as a lender) then it should display ' Sorry but there's no results '. IF both conditions are met then it should display the results. It's so simple in concept but I can't figure out why it won't work. IF $results DISPLAY $results.. IF NO $results DISPLAY this -> message Ken2K7, the query works as is. What's not happening is the display of the 'else' content IF the search doesn't produce results. I don't think the single quotes would make a diff since the query is working without errors. Something is either breaking OR it's possible.... possible... that the reason the page is totally blank is because either PHP or MySQL is timing out on the query for some reason which is causing the script to die. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted January 4, 2008 Share Posted January 4, 2008 Well it's just if the column names are category_1, _2, etc., I've seen people single quote them so I suggested it. And umm...if the query works, I don't see why this isn't working. :S Quote Link to comment Share on other sites More sharing options...
simcoweb Posted January 4, 2008 Author Share Posted January 4, 2008 redarrow, i'm using your code right now. Your latest post. Go to: http://www.lenderfish.com/search-test.php select Purchase in the 1st box and Rate and Term Refinance in the other. You'll see that there's results for that. Go back to the search page and in just the second box select Stated while leaving the first box the same. There's no match for that. See what happens. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted January 4, 2008 Share Posted January 4, 2008 Quick question: can't you check for the 'STATED' value only? Shouldn't matter what the first dropdown is. As long as the second one is 'STATED,' this should display a message right? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.