Results 1 to 3 of 3

Thread: search csv file with php

  1. #1
    Join Date
    Mar 2009
    Thanked 0 Times in 0 Posts

    Question search csv file with php

    Hey, sort of new to php and I need to help using php to open a csv file. It is seperated by user,situation. It will then be searched and displayed by a user to the webpage. I just need to have a text box where people can search by the user and it will display the solution. What is the best way to do this. I was not sure where to begin. Thanks in advance, let me know if I need to explain this better.

  2. #2
    Join Date
    Sep 2008
    Thanked 6 Times in 6 Posts



    Using CSV for such a thing is not good idea as you can only do sequential search in CSV, when the number of records will be more then it will lead to increased execution time and may also result into script timeout. Better is to use some database, MySQL is the best choice with PHP.

    But anyways, when some user searched, you will have to open the CSV file in the read mode, you can do this using file() function and then run a loop to traverse through each and every record and for each record check if in it exists the keywords entered by the user the save it in a temp variable and after the loop have be completed then display the value stored in the temp variable

    If you think there can be multiple records with the matching result then you can keep showing the record in the loop and if you think that there will only be one record then you can break the loop after the record has been found.

    Hope this helps.



  3. #3
    Join Date
    Apr 2008
    Limoges, France
    Thanked 61 Times in 61 Posts


    Can you post an example of the content in your csv file? I am having a tough time picturing what you mean by user,situation.


Posting Permissions

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