Results 1 to 3 of 3

Thread: search csv file with php

  1. #1
    Join Date
    Mar 2009
    Posts
    1
    Thanks
    0
    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
    Posts
    56
    Thanks
    0
    Thanked 6 Times in 6 Posts

    Default

    Hi,

    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.

    Cheers,

    ~Maneet

  3. #3
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    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.

Bookmarks

Posting Permissions

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