Php 在printf()中调用函数()
我有一个Php 在printf()中调用函数(),php,mysql,Php,Mysql,我有一个while()函数,可以循环表中的一行数据。 现在,我需要在每行的一个特定列中有一个下拉列表。 该下拉列表也通过使用循环来执行 下面是创建下拉列表的函数: function createDropdown($total) { $i = 1; echo "<select>"; while($i <= $total) { echo "<option value = '$i' id =* '$i'&g
while()
函数,可以循环表中的一行数据。现在,我需要在每行的一个特定列中有一个下拉列表。
该下拉列表也通过使用循环来执行 下面是创建下拉列表的函数:
function createDropdown($total)
{
$i = 1;
echo "<select>";
while($i <= $total)
{
echo "<option value = '$i' id =* '$i'>$i</option>";
$i++;
}
echo "</select>";
}
function createDropdown($total)
{
$i=1;
回声“;
虽然($i这个怎么样(对不起,我也有点不清楚你在问什么):
function createDropdown($num,$total)
{
$i=1;
$result=“”;
而($i则必须将$id作为参数传递给createDropDown()
函数:
function createDropdown($total, $id = 'somedefaultvalue') {
echo "<select id=\"$id\">";
for (...) {
...
}
echo "</select>"
}
function createDropdown($total,$id='somedefaultvalue'){
回声“;
对于(…){
...
}
回声“”
}
FYI:在像PHP这样的脚本语言中,除非需要使用printf的格式化功能(例如,`printf('%0.2d',3.234234)->'3.23',否则不需要printf.PHP是使用常规双引号字符串将变量插入文本的完美工具,没有printf开销。是的,我意识到了。我的团队中有人喜欢printf。我计划将其更改为简单的回显。
function createDropdown($num, $total)
{
$i = 1;
$result = "<select id='sel$num' name='sel$num'>";
while($i <= $total)
{
$result .= "<option value = '$i' id = '$i'>$i</option>";
$i++;
}
$result .= "</select>";
return $result;
}
$num = 0;
while($row1 = mysql_fetch_array($result1))
{
print("<tr>");
printf("<td>%s %s</td>", $row1["fname"], $row1["lname"]);
printf("<td>".createDropdown($num++, $count)."</td>");
printf("<td colspan = '2'>%s</td>",$count);
printf("`111");
print("");
}
function createDropdown($total, $id = 'somedefaultvalue') {
echo "<select id=\"$id\">";
for (...) {
...
}
echo "</select>"
}