I am working on a Phone Directory list; now when I download the .CSV file from our phone directory it prints only gives me user ID, Extension, Name, and a few other roles that are not very relevant.
My problem is I want to group the Extensions/People by office, and since the spreadsheet does not offer any hints in that sense I thought of creating an array and matching it with my .CSV element.
The office extensions are not very consistent, so for Office A you may have extensions: 103, 215, and 105. Office B may be: 150, 104.
Now I created an array where I group extensions by office, and it looks something like this:
$offices = array(
'Office' => array (
'110',
'107',
'137',
'113'
),
// ...
);
For actually reading the spreadsheet I am using fgetcsv which works very well without any type of filters, but I whenever I try to put in a variation to "filter" the while loop I run into problems.
I tried using MySQL, but this is not a good method because whenever it needs to be updated, someone else will be doing it, and they do not want to work with PHP or MySQL.
This is the code for the list to be shown:
<?php
$file_name = htmlentities($_GET['file']);
// open CSV file
$handle = fopen("./_files/" . $file_name, "r");
$i = 0;
// gets data from csv file
echo "<div class='row'>";
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
// stores dates as variable $date
$date[$i] = $data[0];
$i++;
// create vars
$name = $data[2];
$email = $data[0];
$ext = $data[1];
if ($ext < 400)
{
?>
<div class="col-sm-4">
<ul class="mdc-list mdc-list--dense">
<li class="mdc-list-item">
<span class="mdc-list-item__text">
<?php echo $name; ?>
</span>
<span class="mdc-list-item__end-detail" aria-label="extention">
<?php echo $ext; ?>
</span>
</li>
</ul>
</div>
<?php
}
}
echo "</div>";
?>
Just to reiterate what the problem I need to solve is:
I need to match the results I get from while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) with the $offices array.
For Example
If ( Worker A's extension == 102 ), look inside of the $office array creating an office match and output his $name and $ext under that office section.
whileand then sort it?