SELECT project.id, project.name
FROM project
INNER JOIN project_category ON project_category.project_id = project.id
LEFT JOIN project_order ON project_order.project_id = project.id
WHERE project_category.category_id = $id
AND project_order.category_id = $id
ORDER BY project_order.order ASC
What do you mean "optional"? If you remove the condition altogether then it will be optional.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
WHERE project_category.category_id = $id
AND (project_order.category_id = $id OR project_order.category_id = '')
If it might be null or conatin a zero then use one of those in the condition.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.