Jump to content

reading specific data from csv files


cyberangel

Recommended Posts

hi all,

 

am back again with a problem, and i hope i will get wonderfull help here once again.

what i am actually trying to do is that i have a .csv file wich is supposed to contain information for different room numbers. for example a list of clean and dirty rooms. i wanted to get a php script which can find the room in the list and display only that row. i found a script which works and displays all the rooms list, which is not what i need. the script is as follows:

 

<?php
$row = 1;
$handle = fopen ("test.csv","r");
while ($data = fgetcsv ($handle, 1000, ",")) {
$num = count ($data);
print "<p> $num fields in line $row: <br>\n";
$row++;
for ($c=0; $c < $num; $c++) {
print $data[$c] . "<br>\n";
}
}
fclose ($handle);
?>

 

it actually displays the complete csv file. i am using certian php scripts with mysql, where i have a form page with just 1 or 2 text boxes, it posts the variables to the second page which finds the data in mysql database and displays the result. i want the same to happen with csv file. can anybody please help me? many thanks in advance

 

Link to comment
https://forums.phpfreaks.com/topic/127307-reading-specific-data-from-csv-files/
Share on other sites

hi barand,

 

thanks for the reply. i didn't write the code myself, i just found it in internet  :-[ so i tried to add your code to the while loop somehow. I couldn't actually figure out how to add it. all i need is  to print the room number and status of the room. for example, i want to see if the room number 110 is clean or dirty, i type 110 in the form text field in first page, it reads the csv file which includes the info and shows 110 - clean or 110 - dirty.

i know i should learn more myself to get it done but will appreciate any help. Thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.