sKunKbad Posted April 1, 2006 Share Posted April 1, 2006 ***Nevermind, I fixed it, I should have stayed in bed***I have a problem with this program. You can see that if both $value1 and $value2 are "All" that the results are indeed displayed, but if $value1 and $value2 are not both "All" the resulting page comes up totally blank. Please help:<?php$value1 = "$_POST[subType]";$value2 = "$_POST[city]";{include("./xxxyyyzzz.php");if ($value1 != "All" AND $value2 != "All"){$query = "SELECT * FROM localdirectory WHERE subType = '$value1' AND city = 'value2' "; }if ($value1 == "All" AND $value2 == "All"){$query = "SELECT * FROM localdirectory" ;}}$result = mysql_query($query) or die ("Couldn't execute query."); while ($row = mysql_fetch_array($result)) {extract ($row); ?><?php if($type == "business") { //This is where the business listings get called up by the if statement?><div class="sponsor"><?phpif($sponsorStatus == "yes"){echo "<img src=\"images/sponsor.jpg\" alt=\"this Christian owned business is a site sponsor\"/>";} else {echo " ";}?></div><div class="listing"><?php echo "<strong>$name</strong>";if($address != ""){echo "<br/>\n$address";}if($city != ""){echo "<br/>\n$city",", ";}if($st != ""){echo "$st"," ";}if($zip != ""){echo "$zip";}if($teleNumber != ""){echo "<br/>\n$teleNumber";}if($webAddress != ""){echo "<br/>\nwebsite: <a href=\"$webAddress\">$webAddress</a>";}if($email != ""){echo "<br/>\nemail: <a href=\"mailto:$email\">$email</a>";}echo "</div>\n";?><div class="hrule76"> </div><?phpecho "\n";}} ?>Thanks for any help, Quote Link to comment https://forums.phpfreaks.com/topic/6340-solved-html-form-program-help/ Share on other sites More sharing options...
toplay Posted April 1, 2006 Share Posted April 1, 2006 You forgot the dollar sign on value2 when building the $query variable.[code]if ($value1 != "All" && $value2 != "All") { $query = "SELECT * FROM localdirectory WHERE subType = '$value1' AND city = '$value2' "; // missing $} else { $query = "SELECT * FROM localdirectory";}[/code]You may want to display something when there's no match. Quote Link to comment https://forums.phpfreaks.com/topic/6340-solved-html-form-program-help/#findComment-22912 Share on other sites More sharing options...
sKunKbad Posted April 1, 2006 Author Share Posted April 1, 2006 [!--quoteo(post=360644:date=Apr 1 2006, 09:32 AM:name=toplay)--][div class=\'quotetop\']QUOTE(toplay @ Apr 1 2006, 09:32 AM) [snapback]360644[/snapback][/div][div class=\'quotemain\'][!--quotec--]You forgot the dollar sign on value2 when building the $query variable.[code]if ($value1 != "All" && $value2 != "All") { $query = "SELECT * FROM localdirectory WHERE subType = '$value1' AND city = '$value2' "; // missing $} else { $query = "SELECT * FROM localdirectory";}[/code]You may want to display something when there's no match.[/quote]toplay, can you suggest how to display "your search criteria returned no matches" when there is no match.In the last few minutes I made it to where if one $value=="All" and the other $value !="All" then results are displayed correctly, I just need to have a no match message now.Thanks, Quote Link to comment https://forums.phpfreaks.com/topic/6340-solved-html-form-program-help/#findComment-22915 Share on other sites More sharing options...
toplay Posted April 1, 2006 Share Posted April 1, 2006 There's at least a couple of ways:1) After the mysql_query() and error checking (or die), you can run a mysql_num_rows(). If it's greater than zero, then you have rows and can do the while loop. Otherwise, display no match message.[a href=\"http://us2.php.net/manual/en/function.mysql-num-rows.php\" target=\"_blank\"]http://us2.php.net/manual/en/function.mysql-num-rows.php[/a]2) Set a counter variable to zero before the while loop. Increment it in the while loop. Then after the while loop, check to see if it's zero and display no match message.hth. Quote Link to comment https://forums.phpfreaks.com/topic/6340-solved-html-form-program-help/#findComment-22918 Share on other sites More sharing options...
sKunKbad Posted April 1, 2006 Author Share Posted April 1, 2006 [!--quoteo(post=360650:date=Apr 1 2006, 09:59 AM:name=toplay)--][div class=\'quotetop\']QUOTE(toplay @ Apr 1 2006, 09:59 AM) [snapback]360650[/snapback][/div][div class=\'quotemain\'][!--quotec--]There's at least a couple of ways:1) After the mysql_query() and error checking (or die), you can run a mysql_num_rows(). If it's greater than zero, then you have rows and can do the while loop. Otherwise, display no match message.[a href=\"http://us2.php.net/manual/en/function.mysql-num-rows.php\" target=\"_blank\"]http://us2.php.net/manual/en/function.mysql-num-rows.php[/a]2) Set a counter variable to zero before the while loop. Increment it in the while loop. Then after the while loop, check to see if it's zero and display no match message.hth.[/quote]AWESOME! It worked. I used an if statement where if $num_rows was "" it gives the no match message>Thanks for your help this morning. I haven't slept well lately, and my brain is fryed. Quote Link to comment https://forums.phpfreaks.com/topic/6340-solved-html-form-program-help/#findComment-22925 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.