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

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化