XtremeAU
09-08-2008, 02:43 AM
Hi all,
I have a question in regards to coding to a particular platform. Basically what i have done so far is design a little form, when data is entered and 'submitted' - the entered data writes to a text file. What i have then done is, had the data from the text file display into a html table
What i would like to do now is use what is in the text file and display the relevant data to the chosen category. The data to be entered is as follows: ID, First Name, Last Name, *Department*, Salary, Date of Employment.
Essentially i would like to be able to select from a choice of departments and then see how many employees are in the one department.
What i have done so far.....
This is the code that displays the contents of the text file into a table:
<?php
$bigstring = file_get_contents("records.txt");
$bigarray = explode("\n",$bigstring);
echo "<table border=\"1\" align=\"center\">";
echo "<tr><th>ID</th>";
echo "<th>Given Name</th>";
echo "<th>Family Name</th>";
echo "<th>Department</th>";
echo "<th>Salary</th>";
echo "<th>Date</th></tr>";
foreach ($bigarray as $key => $value) {
$smallarray=explode(":", $value);
echo "<br>";
if (!empty($smallarray[0])){
$id=$smallarray[0];
$gname=$smallarray[1];
$fname=$smallarray[2];
$depart=$smallarray[3];
$salary=$smallarray[4];
$date=$smallarray[5];
echo "<tr><td>";
echo $id;
echo "</td><td>";
echo $gname;
echo "</td><td>";
echo $fname;
echo "</td><td>";
echo $depart;
echo "</td><td>";
echo $salary;
echo "</td><td>";
echo $date;
echo "</td></tr>";
}
}
echo "</table>";
?>
I'm trying to get the 'department' category to display using variations of this code:
<?
$totals=array();
$records = file("records.txt");
foreach ($records as $key => $value) {
$department=explode(":", $value);
print_r($department);
$thisdept = $department[1];
if (array_key_exists($thisdept,$totals)) {
$totals[$thisdept]+=1;
} else {
$totals[$thisdept]=1;
}
print_r($totals);
}
?>
I'd appreciate some pointers as to where i am going wrong.
I have a question in regards to coding to a particular platform. Basically what i have done so far is design a little form, when data is entered and 'submitted' - the entered data writes to a text file. What i have then done is, had the data from the text file display into a html table
What i would like to do now is use what is in the text file and display the relevant data to the chosen category. The data to be entered is as follows: ID, First Name, Last Name, *Department*, Salary, Date of Employment.
Essentially i would like to be able to select from a choice of departments and then see how many employees are in the one department.
What i have done so far.....
This is the code that displays the contents of the text file into a table:
<?php
$bigstring = file_get_contents("records.txt");
$bigarray = explode("\n",$bigstring);
echo "<table border=\"1\" align=\"center\">";
echo "<tr><th>ID</th>";
echo "<th>Given Name</th>";
echo "<th>Family Name</th>";
echo "<th>Department</th>";
echo "<th>Salary</th>";
echo "<th>Date</th></tr>";
foreach ($bigarray as $key => $value) {
$smallarray=explode(":", $value);
echo "<br>";
if (!empty($smallarray[0])){
$id=$smallarray[0];
$gname=$smallarray[1];
$fname=$smallarray[2];
$depart=$smallarray[3];
$salary=$smallarray[4];
$date=$smallarray[5];
echo "<tr><td>";
echo $id;
echo "</td><td>";
echo $gname;
echo "</td><td>";
echo $fname;
echo "</td><td>";
echo $depart;
echo "</td><td>";
echo $salary;
echo "</td><td>";
echo $date;
echo "</td></tr>";
}
}
echo "</table>";
?>
I'm trying to get the 'department' category to display using variations of this code:
<?
$totals=array();
$records = file("records.txt");
foreach ($records as $key => $value) {
$department=explode(":", $value);
print_r($department);
$thisdept = $department[1];
if (array_key_exists($thisdept,$totals)) {
$totals[$thisdept]+=1;
} else {
$totals[$thisdept]=1;
}
print_r($totals);
}
?>
I'd appreciate some pointers as to where i am going wrong.
