Jump to content


Photo

*SOLVED* HTML form program help


  • Please log in to reply
4 replies to this topic

#1 sKunKbad

sKunKbad
  • Members
  • PipPipPip
  • Advanced Member
  • 1,832 posts
  • LocationTemecula, CA, USA

Posted 01 April 2006 - 05:20 PM

***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,
Brian's Web Design - Temecula

Freedom is only available through death.

#2 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 01 April 2006 - 05:32 PM

You forgot the dollar sign on value2 when building the $query variable.

if ($value1 != "All" && $value2 != "All") {
    $query = "SELECT * FROM localdirectory WHERE subType = '$value1' AND city = '$value2' "; // missing $
} else {
    $query = "SELECT * FROM localdirectory";
}

You may want to display something when there's no match.



#3 sKunKbad

sKunKbad
  • Members
  • PipPipPip
  • Advanced Member
  • 1,832 posts
  • LocationTemecula, CA, USA

Posted 01 April 2006 - 05:50 PM

[!--quoteo(post=360644:date=Apr 1 2006, 09:32 AM:name=toplay)--][div class=\'quotetop\']QUOTE(toplay @ Apr 1 2006, 09:32 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
You forgot the dollar sign on value2 when building the $query variable.

if ($value1 != "All" && $value2 != "All") {
    $query = "SELECT * FROM localdirectory WHERE subType = '$value1' AND city = '$value2' "; // missing $
} else {
    $query = "SELECT * FROM localdirectory";
}

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,

Brian's Web Design - Temecula

Freedom is only available through death.

#4 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 01 April 2006 - 05:59 PM

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.


#5 sKunKbad

sKunKbad
  • Members
  • PipPipPip
  • Advanced Member
  • 1,832 posts
  • LocationTemecula, CA, USA

Posted 01 April 2006 - 06:34 PM

[!--quoteo(post=360650:date=Apr 1 2006, 09:59 AM:name=toplay)--][div class=\'quotetop\']QUOTE(toplay @ Apr 1 2006, 09:59 AM) View Post[/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.


Brian's Web Design - Temecula

Freedom is only available through death.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users