Log in

View Full Version : To read data from CSV file and print the values in Select field of a form



coolest_coder
11-12-2008, 09:57 AM
Hello everyone,

I am reading a .csv file:

<?php

$file = fopen("groups.csv","r");

while(!feof($file))
{
$groups2 = fgetcsv($file,",");
print_r($groups2);
}

fclose($file);

?>

The file is read successfully. But now i need to call this file in another file and the groups fetched from this file are to be placed in a select field of the form.

Can anyone please help me how to do this?

Thank you.

maneetpuri
11-12-2008, 12:19 PM
Hi,

This is simple..... :-)!

Start a form tag just before the while loop and in the while loop where you are displaying value of Group2 there add this line: -

echo ("<input type=text name= ". $i . " value=" . $group2 . ">");

Where $i will be a counter to name each text box differently, after the loop create a hidden filed and set value of $i as its value. Now when you will submit this form the value of this hidden field will tell you how many text boxes where created and then you can access them all.

Hope this makes sense!

Cheers,

~Maneet
LeXolution IT Services
Website Design Services (http://www.lexolutionit.com/services.php)

coolest_coder
11-12-2008, 04:25 PM
I go it the way you said :)

Thank you.