Jump to content

*SOLVED* HTML form program help


sKunKbad

Recommended Posts

***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">
<?php
if($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><?php
echo "\n";
}
}
?>



Thanks for any help,
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

[!--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,
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

[!--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.

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.