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 Summarizing Project Time

johnny louifils
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
johnny louifils
Full Stack JavaScript Techdegree Graduate 18,926 Points

summarizing project time 2

I get this error : Error:: SQLSTATE[HY000]: General error: 1 near "BY": syntax error

$sql = 'SELECT tasks.*, projects.title as project FROM tasks JOIN projects ON tasks.project_id = projects.project_id';

$orderBy = 'ORDER BY date DESC'; if ($filter) { $orderBy = 'ORDER BY projects.title ASC, date DESC'; }

try {
    $results = $db->prepare($sql . $orderBy);
    $results->excute();
} catch (Exception $e) {
  echo "Error:: " . $e->getMessage() . " </br>";
  return array();
}
return $results->fetechAll(PDO::FETCH_ASSOC);

}

1 Answer

Try with a space before ORDER. This:

$orderBy = ' ORDER BY

instead of this:

$orderBy = 'ORDER BY 

Otherwise your SQL looks like this:

tasks.project_id = projects.project_idORDER BY

Also I believe you meant to type

$results->fetchAll

instead of

$results->fetechAll

and

$results->execute

instead of

$results->excute