The forums have permanently moved to This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.

Results 1 to 4 of 4

Thread: howto: sort a csv file in numeric order

  1. #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>
    //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_handle1024);
    //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>

  2. #2
    id use this awesome class over at google code - it has this capability built in:

  3. #3
    $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];
    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

  4. #4
    It is not sorting

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Home About Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012