mercredi 11 août 2021

If statement is only checking that last iteration in while loop PHP

I'm familiar with programming in general but what I'm facing is a bit weird. The if statement is only working on the last iteration:

Output: IN IN OUT OUT OUT OUT IN OUT IN BIN BOUT OUT OUT OUT OUT

However if I add an if statement it only performs on the last iteration:

<?php

$conn = mysqli_connect('localhost','root','','text');

if(!$conn)
{
    die(mysqli_error());
}


$open = fopen('test.txt','r');
while (!feof($open)) 
{
    
    $getTextLine = fgets($open);
    $explodeLine = explode(",",$getTextLine);
    list($Date,$ID,$Status) = $explodeLine;
    
    if($Status == "OUT"){
        echo "$Status";
    }

}
fclose($open);
?>

Output: OUT

Text file:

19-04-21 13:41:38  ,0000000917         ,IN
19-04-21 13:49:50  ,0000001310         ,IN
19-04-21 13:52:24  ,0000000505         ,OUT
19-04-21 13:53:36  ,0000000546         ,OUT
19-04-21 14:05:24  ,0000001267         ,OUT
19-04-21 14:05:32  ,0000001228         ,OUT
19-04-21 14:06:26  ,0000000454         ,IN
19-04-21 14:13:10  ,0000000990         ,OUT
19-04-21 14:17:32  ,0000001354         ,IN
19-04-21 14:27:04  ,0000000325         ,BIN
19-04-21 14:27:18  ,0000000325         ,BOUT
19-04-21 14:31:12  ,0000000649         ,OUT
19-04-21 14:32:22  ,0000000061         ,OUT
19-04-21 14:33:00  ,0000001301         ,OUT
19-04-21 14:34:34  ,0000000548         ,OUT

Aucun commentaire:

Enregistrer un commentaire