I don't believe you can without using a subquery. The DISTINCT keyword is what's going to get you.
So you can either run the query on its own (it's a fast query), or use a subquery and include it's output in the response:
$result = mysql_query("
SELECT DISTINCT
l.categoryid , lc.name, lc.id, cnt.`total`
FROM
`layouts` AS l
LEFT JOIN
`lcategories` AS lc
ON l.`categoryid` = lc.`id`
LEFT JOIN (
SELECT COUNT(*) AS `total`, `categoryid`
FROM `layouts`
GROUP BY `categoryid`
) AS cnt
ON lc.`id` = cnt.`categoryid`
ORDER BY lc.`name`
");