在选项值中使用函数我需要一些帮助。 我刚开始使用/学习函数并写了这个:
*function selectNew($dbcon) {
$sql = 'SELECT id, item, comment, date, time, important FROM item ORDER BY ASC id';
foreach ($dbcon->query($sql) as $row) {
print $row['item'] . "\t";
print $row['comment'] . "\t";
print $row['date'] . "\n";
print $row['time'] . "\n";
print $row['important'] . "\n";
}
}*
我想在下面使用它:
<table>
<tr><th>Select by:</th><td><select>
<option value="<?php selectNew ?>">Newest</option>
</select></td></tr>
</table>
如果我选择此项,我想按ID按升序回显数据库中的数据。
这是可能的还是我需要以其他方式做到这一点?
谢谢,
答案 0 :(得分:0)
您需要在循环中输出选项标记。
function selectNew($dbcon) {
$sql = 'SELECT id, item, comment, date, time, important FROM item ORDER BY ASC id';
foreach ($dbcon->query($sql) as $row) {
echo "<option>";
print $row['item'] . "\t";
print $row['comment'] . "\t";
print $row['date'] . "\n";
print $row['time'] . "\n";
print $row['important'] . "\n";
echo "</option>";
}
}
<table>
<tr><th>Select by:</th><td><select>
<?php selectNew($dbConn); ?>
</select></td></tr>
</table>