Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,833 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