Jump to content

*solved function improper parameters?


Ninjakreborn

Recommended Posts

I have this
[code]<?php
function 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]<?php
select("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?
Link to comment
https://forums.phpfreaks.com/topic/27893-solved-function-improper-parameters/
Share on other sites

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]<?php
function 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]<?php
select('actiontaken[goaround]', 'Go Around', 'Go Around');
?>[/code]

So, what was the problem?

Ken
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.