Example (not tested) $fp = fopen('file.csv', 'r'); // open file for reading
while ($data = fgetcsv ($fp, 1000, ",")) { // read each line of file if ($data[1] == $key) { // determine if key matches the current row $name = $data[1]; // assign information to variables break; // quit the while loop and continue the script } } Where $name = $data[1] is where you would assign the information to variables or an array or call a function with the parameters you want. This is going to be considerably slower than using a database server. Jason -----Original Message----- From: Kevin Stone [mailto:[EMAIL PROTECTED]] Sent: Tuesday, September 10, 2002 2:25 PM To: Ram K; [EMAIL PROTECTED] Subject: Re: [PHP] Strore Data in File RK, this is ultra-basic stuff. Opening and dealing with files is one of the first things you learn with any language. I would highly recommend buying a beginners guide to PHP book and learning thist stuff on your own. But for now this will get you started... <? //Open a file into an array.. $rows = file('table.txt'); //Separate each row into fields.. for ($i=0; $i<count($rows); $i++) { $table[] = explode(',', $rows[$i]); } //Print table.. echo "<table border=2>\n"; for ($i=0; $i<count($table); $i++) { echo "<tr>\n"; for ($j=0; $j<count($table[$i]);$j++) { echo "<td>".$table[$i][$j]."</td>\n"; } echo "</tr>\n"; } echo "</table>"; ?> Good luck. -Kevin ----- Original Message ----- From: "Ram K" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Tuesday, September 10, 2002 11:29 AM Subject: [PHP] Strore Data in File > Hi > > I want to store the data of a table in a file and read that file > just as one would read a table. For e.g. I have a table t_data > with cols name,number,cost and my data file data.txt would have > the following data: > ------- > john,1,100 > mark,2,200 > spencer,3,200 > ------- > > Now on the web page when the visitor clicks on a link on "john" > then this file (data.txt) must be read and the data should be > displayed for "john" i.e. > name = john > number = 1 > cost = 100 > must be displayed > > Can anyone please give me the code to parse this file and read the > data for john and get all the data for that row. Please see that > "john" functions as the primary key in the table > > Regards > Ram > > > __________________________________________________________ > Give your Company an email address like > ravi @ ravi-exports.com. Sign up for Rediffmail Pro today! > Know more. http://www.rediffmailpro.com/signup/ > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php