Ninjakreborn Posted November 20, 2006 Share Posted November 20, 2006 I have this[code]<?phpfunction select($name, $label, $value, $priority) { if ($priority == 1) { $select = "selected=\"selected\""; } echo "<td style=\"text-align:right;\"><input name=\"{$name}\" type=\"checkbox\" value=\"{$value}\" {$select} /></td>\n"; echo "<td style=\"text-align:left;\"><label for=\"{$name}\">{$label}</label></td>\n";}?>[/code]I am calling it in multiple places, like[code]<?phpselect("actiontaken[goaround]", "Go Around", "Go Around", 0);?>[/code]I feed it either 0-1 depending on the situation, and it's returning[quote]Warning: Missing argument 4 for select() in /home/ninksafe/public_html/master/config/functions/validation.inc.php on line 84[/quote]I don't understand why the error is appearing there? Quote Link to comment https://forums.phpfreaks.com/topic/27893-solved-function-improper-parameters/ Share on other sites More sharing options...
Ninjakreborn Posted November 20, 2006 Author Share Posted November 20, 2006 I got it*solvedthanks. Quote Link to comment https://forums.phpfreaks.com/topic/27893-solved-function-improper-parameters/#findComment-127535 Share on other sites More sharing options...
kenrbnsn Posted November 20, 2006 Share Posted November 20, 2006 I'm not sure why you're getting that warning message, but I would change your code slightly to make the 4th parameter optional and pass it the boolean "true" or "false".Function:[code]<?phpfunction select($name, $label, $value, $priority=false) { // if the 4th parameter is not specified when invoking the procedure, it will default to "false" $select = ($priority)?$select = 'selected="selected"':''; // why escape the double quotes when you can enclose the enitire string in single quotes echo '<td style="text-align:right;"><input name="' . $name . '" type="checkbox" value="' . $value . '" ' . $select . '/></td>' . "\n"; echo '<td style="text-align:left;"><label for="' . $name . '">' . $label . '</label></td>' . "\n";}?>[/code]Invocation:[code]<?phpselect('actiontaken[goaround]', 'Go Around', 'Go Around');?>[/code]So, what was the problem?Ken Quote Link to comment https://forums.phpfreaks.com/topic/27893-solved-function-improper-parameters/#findComment-127536 Share on other sites More sharing options...
Ninjakreborn Posted November 20, 2006 Author Share Posted November 20, 2006 Well I had solved it, but now I see 2 new things you mentioned I didn't know, I will keep those in mind and play with them, I knew about the quote's, but I always used double because you can't extrapolate with singlle, but i have also started using concatenations (excuse spelling, don't feel like looking it up), I started using those so single quotes might be the way to go.Thanks again for the advice. Quote Link to comment https://forums.phpfreaks.com/topic/27893-solved-function-improper-parameters/#findComment-127543 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.