dqxmf02844 2009-12-08 11:53
浏览 12
已采纳

html php和选择框简化

Is there a better way to structure this, using html and php?

If I had a billion values, this would be a bad way to set them up, not to mention time consuming as well?

I am a newb, and I am pretty sure there is a better way, however, my way of doing it seems to be the long way, as in long division, I am pretty sure there are easier methods of setting this up, and that's what I am looking for, or asking?

<select name="dimes" >
    <option value=" ">--Select Dimes---</option>
    <option value=".10">10c</option>
    <option value=".20">20c</option>
    <option value=".30">30c</option>
    <option value=".40">40c</option>
    <option value=".50">50c</option>
    <option value=".60">60c</option>
    <option value=".70">70c</option>
    <option value=".80">80c</option>
    <option value=".90">90c</option>
    <option value="1.00">$1.00</option>
    </select>

Thank you for not flaming the Newb, I am still learning.

  • 写回答

2条回答 默认 最新

  • doushi2902 2009-12-08 12:08
    关注

    If you prefer to use mixed PHP & HTML, you can use such construction:

    <select name="dimes" >
        <option value=" ">--Select Dimes---</option>
        <?php foreach($dates as $key=>$value): ?>
          <option value="<?php echo $key; ?>">
            <?php echo $value; ?>
          </option>
        <?php endforeach; ?>
    </select>
    

    Note, that you have to define and fill $dates array before using it in foreach statement. You can fill $dates with any data your want. In this example array has to be something like: array('0.1'=>'0.1', '0.2'=>'0.2'); But also your can go futher and use result of MySQL queries to fill array with keys and values. See foreach for more details.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题