PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
facets
Forum Contributor
Posts: 273 Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit
Post
by facets » Fri Jul 01, 2005 9:37 pm
Hi All,
I didn't get any response from my previous post so I thought i'd simplify things.
Can anyone tell me why the results, in this case, 'echo "RESULTS"' is being displayed above the search button?
tia, will.
Code: Select all
<?
if (isset($_POST['searchNow'])) {fnSearchResults();}
function fnSearchResults() {
echo "RESULTS";
}
function viewSearch() {
echo "<form method=\"post\" action=\"".$_SERVER['PHP_SELF']."\">\n";
echo "<input type=\"submit\" name=\"searchNow\" class=\"btn\" value=\"Search Now\">";
}
viewSearch();
?>
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Fri Jul 01, 2005 10:03 pm
beacause that's where your function is.
if you want the results displayed somewhere else, you need to set a var and have the function "return" the value:
ex:
Code: Select all
function foo($bar){
$var = "I am foo".$bar;
return $var;
}
$bob = foo("lish");
echo $bob;
//yeilds 'I am foolish'
facets
Forum Contributor
Posts: 273 Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit
Post
by facets » Fri Jul 01, 2005 10:25 pm
closer, how do I only display this once the submit is executed.
Code: Select all
if (isset($_POST['searchNow'])) {fnSearchResults();}
function viewSearch() {
echo "<form method=\"post\" action=\"".$_SERVER['PHP_SELF']."\">\n";
echo "<input type=\"submit\" name=\"searchNow\" class=\"btn\" value=\"Search Now\">";
}
viewSearch();
function fnSearchResults() {
$var = "<br><br>Results";
return $var;
}
$bob = fnSearchResults();
echo $bob;
tia, Will.
PS. Sorry for the foolish questions
facets
Forum Contributor
Posts: 273 Joined: Wed Apr 13, 2005 1:53 am
Location: Detroit
Post
by facets » Fri Jul 01, 2005 10:53 pm
This seems to work.
Code: Select all
<?
viewSearch();
function fnSearchResults() {
echo "RESULTS";
}
function viewSearch() {
echo "<form method=\"post\" action=\"".$_SERVER['PHP_SELF']."\">\n";
echo "<input type=\"submit\" name=\"searchNow\" class=\"btn\" value=\"Search Now\">";
}
if (isset($_POST['searchNow'])) {fnSearchResults();}
?>