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];
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害