dr200166 2013-01-29 17:47
浏览 33
已采纳

CSV数据作为PHP表单选项拉入

I have a CSV file (say "../datarange.csv", made up of 8 columns and a variable amount of rows deep:

HEADER1,HEADER2,HEADER3...HEADER8
DATA001,DATA122,DATA355...DATA888
DATA002,DATA102,DATA322...DATA876
DATA003,DATA176,DATA344...DATA811
                DATA435...DATA222
                DATA311

I want to pull in only the data under "HEADER8" and have it populate a drop-down "option select" menu in a form using PHP. Each individual like down under "HEADER8" will be it's own individual option.

The idea is that users, on another form, submit data to populate "HEADER8" with suggested names, like brainstorming for a new feature's name. THIS form is to allow users to vote on the final selection and the form will write to a new CSV (this works fine though - I just need to pull in the CSV data from the previous CSV and make it the option menu in this form).

I don't need to pull it from a database or even touch MySql - only part of this I'm having trouble with is pulling from the old CSV to create the drop-down selection menu.

I appreciate the help!

  • 写回答

1条回答 默认 最新

  • douchuo0730 2013-01-29 18:02
    关注

    fgetcsv should help you here.

    $header8 = array();
    if (($handle = fopen("../datarange.csv", "r")) !== FALSE) {
        while (($data = fgetcsv($handle)) !== FALSE) {
            //input logic to skip first row
            $header8[$data[7]] = $data[7];
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

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