Reading Specific Lines of a csv File into a Table

ساخت وبلاگ
Hello

I'm fairly new to php so hope someone can assist

I have a file with 11 rows that I can read into a table without any problems (code below).

What I'm now looking to do is read certain lines of the csv file dependent on the value of one of the rows

For example I would like to read only lines where Line [0] (Section) equals A.

Can anyone point me in the right direction

Many Thanks

PHP Code:


<?PHP

//csv Row Values

// Line [0] = Section 
// Line [1] = Team Number
// Line [2] = Team Name
// Line [3] = Home Alley
// Line [4] = Home Night
// Line [5] = Captain
// Line [6] = Vice Captain
// Line [7] = Captain Telephone
// Line [8] = Vice Captain Telephone
// Line [9] = Food
// Line [10] = ID

// Open the CSV File you wish to read

$file fopen("csv/testlist.csv""r");

// initialize a loop to go through each line of the file
while (!feof ($file)) {

$line fgetcsv($file4096);

if (
$line[6] == '') { $line[6] = 'n/a'; }
if (
$line[8] == '') { $line[8] = 'n/a'; }


echo
"<table border='1' width='100%' id='table1'>n";
echo
"<tr>n";
echo
"<td>$line[0]</td>n";
echo
"<td>$line[1]</td>n";
echo
"<td>$line[2]</td>n";
echo
"<td>$line[3]</td>n";
echo
"<td>$line[4]</td>n";
echo
"<td>$line[5]</td>n";
echo
"<td>$line[6]</td>n";
echo
"<td>$line[7]</td>n";
echo
"<td>$line[8]</td>n";
echo
"<td>$line[9]</td>n";
echo
"<td>$line[10]</td>n";
echo
"</tr>n";
echo
"</table>n";

  
fclose($file);

?>

CodingForums...
ما را در سایت CodingForums دنبال می کنید

برچسب : نویسنده : codingforums بازدید : 309 تاريخ : چهارشنبه 6 تير 1397 ساعت: 3:36