普通网友 2017-04-03 15:53
浏览 70

如何在select输入类型中使用函数

I need some help with using a function in a option value. I just started using/learning functions and wrote this :

*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'] . "
";
    print $row['time'] . "
";
    print $row['important'] . "
";
  }
}*

i want to use this in :

<table>
    <tr><th>Select by:</th><td><select>
      <option value="<?php selectNew ?>">Newest</option>
    </select></td></tr>
</table>

If i select this i want to echo the data from my database in ascending order by id.

Is this possible or do i need to do this in a other way?

Thanks,

  • 写回答

1条回答 默认 最新

  • dsvtnz6350 2017-04-03 15:58
    关注

    You'll want to output your option tags from within the loop.

    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'] . "
    ";
        print $row['time'] . "
    ";
        print $row['important'] . "
    ";
        echo "</option>";
      }
    }
    
    <table>
        <tr><th>Select by:</th><td><select>
          <?php selectNew($dbConn); ?>
        </select></td></tr>
    </table>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号