Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP CRUD Operations with PHP Reading and Writing Reports Filtering Data

Lewis Cowles
Lewis Cowles
74,902 Points

optional PDO parameters

The question doesn't make sense, looking at preview it shows left and right as identical with a notice i'm assuming in the test that checks my code as I'm not using [0] anywhere...

Alena Holligan can you check it out or point me in the right direction

index.php
<?php
function get_people($filter=false) {
    include 'connection.php';
    try {
      $query = 'SELECT * FROM people ' . ($filter ? 'WHERE treehouse = ?' : '') . ' ORDER BY last_name DESC';
      $stmt = $db->prepare($query);
      if($filter) {
        $stmt->bindValue(1, 1);
      }
      $stmt->execute();
      return $stmt->fetchAll(PDO::FETCH_ASSOC);
    } catch(Exception $e) { return []; }
}

1 Answer

Lewis Cowles
Lewis Cowles
74,902 Points

Test required null instead of more precise boolean false... just a strange way to approach the problem. Personally I use status bits instead of additional fields so I can perform a single operation and verify a number of criteria are acceptable, so I'll always bind the status bits and I just need to perform a bitwise or operation to filter teachers in or out.