Results 1 to 4 of 4
-
March 19th, 2008, 02:02 AM #1
howto: sort a csv file in numeric order
I want to sort the csv file in numeric order using the coloum id
I tried sort_numeric and it would not work maybe I was not using it correctly.
I want to sort this dropdown list, numerically by it value.
PHP Code:<option value="0"> Select your State </option>
<?PHP
//open csv file then display the result in the dropdown list
$file_handle = fopen("file1.csv", "r");
while (!feof($file_handle) ) {
$line_of_text = fgetcsv($file_handle, 1024);
//define coloum needed to be displayed from the csv file.
$index = $line_of_text[0];
$value = $line_of_text[1];
?>
<option value="<?php print $index; ?>"> <?php print $value; ?> </option>
<?php
}
?></select><?php
fclose($file_handle);
?>php / mysql / flash / xml

- www.ChampsJamaica.com
-- www.FashionsJamaica.com
--- www.RealJamaicaEstate.com
-
March 19th, 2008, 04:09 AM #2670Registered User
postsid use this awesome class over at google code - it has this capability built in:
http://code.google.com/p/parsecsv-for-php/
-
March 19th, 2008, 04:23 AM #3Code:
$sorted_arr = Array(); $i = 0; while (!feof($file_handle) ) { $line_of_text = fgetcsv($file_handle, 1024); //define coloum needed to be displayed from the csv file. $sorted_arr[$i][0] = $line_of_text[0]; $sorted_arr[$i][1] = $line_of_text[1]; $i++; } ksort( $sorted_arr ); for( $i = 0; $i < count($sorted_arr); $i++ ) { echo " <option value='" . $sorted_arr[$i][0] . "'>" . $sorted_arr[$i][1] . "</option>"; }
the world is getting more complex because people need simple solutions
-
March 21st, 2008, 10:49 AM #4
It is not sorting
php / mysql / flash / xml

- www.ChampsJamaica.com
-- www.FashionsJamaica.com
--- www.RealJamaicaEstate.com

Reply With Quote

Bookmarks