Forum Moderators: coopster

Message Too Old, No Replies

question about function

         

drooh

12:09 am on Mar 13, 2008 (gmt 0)

10+ Year Member



Why is this not working?

$print_type = "flyer";

function check_print_type($type){
if($type == $print_type){
$var = "selected = \"selected\"";
return $var;
} else {
$var = "";
return $var;
}
}

<select size="1" name="print_type">
<option></option>
<option value="banner" <?php echo check_print_type("banner"); ?>>banner</option>
<option value="flyer" <?php echo check_print_type("flyer"); ?>>flyer</option>
</select>

cameraman

12:16 am on Mar 13, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Inside the function you need to declare print_type as global:
global $print_type;

drooh

2:53 am on Mar 13, 2008 (gmt 0)

10+ Year Member



thats it, thank you sir!

so im assuming this is the nuts and bolts of what they call object orientation..?

coopster

2:00 pm on Mar 13, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Nope. Variable scope [php.net] :)