get varialbe of one function from another function
Posted: Tue Oct 10, 2006 9:13 pm
feyd | Please use
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
In the following script the function showvalues cannot recognize the variable dessert because the variable is initialized
in another function?....How can one function get to recognize the variables initialized in another function?
Can someone please improve this code...BTW I want to retain the table in echo format.
thanks so muchCode: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<code>
<html>
<head>
<title>Untitled</title>
</head>
<body>
<form method="post" action="untitled.php">
<a href="untitled.php?action=showtable">Show Table</a>
<a href="untitled.php?action=showvalues&msguid=$msguid">Show Values</a>
<?php
function showtable(){
echo "<table>\n";
echo "<input type=\"submit\" name=\"submit\" value=\"Submit me!\" />\n";
echo "Do you like ice cream?\n";
echo "<input type=\"CHECKBOX\" name=\"dessert[]\" value=\"ice cream\">\n";
echo "<br>\n";
echo "Do you like cake?";
echo "<input type=\"CHECKBOX\" name=\"dessert[]\" value=\"cake\">\n";
echo "<br>\n";
echo "Do you like mint candies?";
echo "<input type=\"CHECKBOX\" name=\"dessert[]\" value=\"mint candies\">\n";
echo "<br>";
echo "</table>\n";
}
function showvalues(){
if (!is_array($_REQUEST['dessert'])) echo "not an array"; ///is always returned
echo $_REQUEST['dessert'];
echo $_REQUEST['dessert'][0];
echo $_REQUEST['dessert'][1];
echo $_REQUEST['dessert'][2];
}
switch ($action) {
case "showtable":
showtable();
break;
case "showvalues":
showvalues();
break;
default:
showtable();
break;
}
?>
</form>
</body>
</html>
</code>feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]