So I have an array and form with input where I put an ID that should show the corresponding row from the array.
So far I have made this:
<?php
$file = 'people.txt';
$people = array();
$ref = fopen($file, 'r');
while ($row = fgets($ref, 1024)) {
$row = explode("|", $row);
$id = $row[0];
$name = $row[1];
$status = $row[2];
$people[$id] = array('name' => $name, 'status' => $status);
}
fclose($ref);
foreach($people as $id => $person) {
if($_GET[person]==$id && $person[status]==1) {
echo $person[name] . "(" . $id . "): ready";
}
if($_GET[person]==$id && $person[status]==0) {
echo $person[name] . "(" . $id . "): not ready";
}
if($_GET[person]!=$id) {
echo "Person with this ID was not found";
}
}
?>
This shows the correct info of searched ID, but it also shows "person was not found" to every other person in the array. How can I get it to show only the person that matches the input?
statusandnameas constants, you will get a lot of php warnings. Better to use quotes e.g.$person["status"]