Question: I'm doing a code based on two .txt, one with names and the other with birthdays. I'm reading them and when the day date coincides with the date.txt, the name in the coincident line of the names.txt will be shown, but when I do the comparison, only the last line of the names.txt appears.

That's the code:

```
<?php

    $nome   =   fopen("nome.txt", "r");
    while(!feof($nome)){
        $pessoa =   fgets($nome);
    }   fclose($nome);

    $current    =   date("d-m");
    $content    =   fopen("data.txt", "r");

    while (!feof($content)){
        $linha  = fgets($content);
        if (strtotime($linha)   ==  strtotime($current))   {
            echo $pessoa;
            echo '<br>';
        }
    }   fclose($content);

    ?>

```

Content of the .txt:

---

nome.txt:

teste

teste1

teste2

teste3

---

data.txt:

12-12

18-12

12-12

12-12

Answer: 
Try this instead of `IFNULL` function
because `IFNULL()`may produce errors if both `cart.item` and `item.id` are null.

```
SELECT `item`.*,
IF(cart.Item is null, Item.ID, cart.Item) AS Button
FROM `item`
LEFT JOIN `cart` ON `cart`.`Item` = `item`.`ID`
AND `cart`.`User` = 3
GROUP BY `item`.`ID`
ORDER BY `item`.`ID`;

```
You may use the COALESCE() function, like this:

```
SELECT `item`.*,  COALESCE(cart.Item, Item.ID) AS Button

```

This will return the second argument Item.ID when cart.item is NULL