to return an html result in loop in a function to a different page
I have a class
class files{
function displayhtml(){?>
select name="df">
for($i=0;$i<10;$i++){?>
<option value="<?php echo "$i"; ?开发者_如何学运维>"><?php echo "$i"; ?></option><?php
}?></select><?php
}
}
?>
I have a file newgetfile.php, i need to display this drop down in newgetfile.php by calling this function in newgetfile.php
You need to use the html part as string.
function displayhtml(){
$string = '<select name="df">';
for($i=0;$i<10;$i++){?>
$string .= '<option value="' . $i .'">' . $i . '</option>';
}
$string .= '</select>';
return $string;
}
class files
{
public static function displayhtml() {
$string = '<select name="df">';
for($i = 0; $i < 10; $i++) {
$string .= '<option value="' . $i .'">' . $i . '</option>';
}
$strin .= '</select>';
return $string;
}
}
echo files::displayhtml();
You can take all drop down code in one php variable and can return it to where you want to display it..
精彩评论