Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Filtering CSV File 1

Status
Not open for further replies.

Yaik

Programmer
Oct 1, 2010
36
US
To start with, I am going to say that I am not using a database at all.

I have a script that takes a CSV file and displays it to the site I need it to.

What I would like to be able to do is have a search box, in which a user can filter the results. Is there any way of doing this without using a database?
 
is there any way of doing this without using a database

yes.

let us know if you need more help. give examples of the types of searches and the structure of your data.
 
Its possible, but depending on the size of the CSV file it may cause it to time out, or take unmanageably long times to search.

Code:
$contents=file("path/to/file.csv");

foreach($contents as $line){
  if(in_array($searchkeyword,$line){
    $results[]=$line;
  }
}


At the end this would produce an array with the the results if any based on $searchkeyword;


----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
That looks like much more than I wanted. Thank you very much. I'll see if I can get it to work with my demo.
 
you should be able to. it's as easy as incuding the libraries and doing this

Code:
<script type="text/javascript" >
$('document').ready(function(){
 $('table').dataTables();
));

then you can add skins and other options to it as you wish. the API is thoroughly documented albeit not very clearly.
 
is not clear at all, i try putting that piece of code in my code, but absolutely nothing is happening.
 
you need to include the libraries too...

if you do not know how to include the required jquery libraries then take a trip to the javascript forum
 
thanks for all the help mate, :D.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top