Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8769287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:18:09+00:00 2026-06-13T17:18:09+00:00

Is is possible to create a select menu in HTML from a CSV file?

  • 0

Is is possible to create a select menu in HTML from a CSV file? I have no idea how to go about this.

So I have a CSV that has two columns and multiple values, is there any way I can loop through the CSV file with PHP and output HTML, I have tried this so far.

$row = 1;
    if (($handle = fopen($_SERVER['DOCUMENT_ROOT']."/service/regions.csv", "r")) !== FALSE) {
        while (($data = fgetcsv($handle, 133, ",")) !== FALSE) {
            $num = count($data);
            $row++;
            for ($c=0; $c < $num; $c++) {
                echo "<option value='".$data[$c]."'>".$data[$c]."</option>";
            }
        }
        fclose($handle);
    }

However this is giving the following output,

 <select>
    <option value='AB'>AB</option>
    <option value='Aberdeenshire'>Aberdeenshire</option>
    <option value='AG'>AG</option>
    <option value='Angus'>Angus</option>
    <option value='AM'>AM</option>
    <option value='Armagh'>Armagh</option>
 </select>

What I am wanting is to get the output like this,

<option value="AB">Aberdeenshire</option>

Where am i going wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T17:18:11+00:00Added an answer on June 13, 2026 at 5:18 pm

    All you need is

    $handle = fopen(__DIR__ . "/service/regions.csv", "r");
    echo "<select>";
    if ($handle !== FALSE) {
        $row = 0;
        while ( ($data = fgetcsv($handle, 133, ",")) !== FALSE ) {
            printf('<option value="%s">%s</option>', $data[0], $data[1]);
        }
        fclose($handle);
    }
    echo "</select>";
    

    Output

    <select>
        <option value="AB">Aberdeenshire</option>
        <option value="AG">Angus</option>
        <option value="AM">Armagh</option>
    </select>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

At the moment I have a PHP/HTML select box that is created dynamically from
Is it possible to create a nested select statement something like this in mysql?
Is it possible to create a select tag from the models validation without having
I have to create File/Folder management system. In which user can select multiple files/folder
Possible Duplicate: Create a CSV File for a user in PHP I am looking
Is it possible to create a MySQL select statement that uses an expression as
Is it possible to create an html checkbox form that will output to a
Is it possible to dynamically create a select statement with multiple where() clauses? Suppose
Possible Duplicate: Create an alert on any view controller after Facebook request:didFailWithError: I have
Possible Duplicate: Create Excel file in Java How to save output in excel format

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.