You can fix your syntax error like this, using another concatenation operator . to append the ORDER BY clause:
$sql = "SELECT item_id,field FROM item WHERE department=".$catid." ORDER BY field";
As long as $catid is an integer, that will work, but it may leave you open to SQL injection, dependent on the source of the value in $catid.
Best practice is to use a prepared query. For MySQLi, something like this:
$sql = "SELECT item_id,field FROM item WHERE department=? ORDER BY field";
$stmt = $conn->prepare($sql);
$stmt->bind_param('i', $catid); // change to 's' if $catid is a string
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
// do something with results
}
ORDER BY fieldis an obvious syntax error. Are you using error reporting? It is the same as you wrote your other string encapsulation,"SELECT ...BUT realllly you shouldn't be doing this at all. The query should beSELECT item_id,field FROM item WHERE department= ? ORDER BY fieldthen bind$catid.$catidis an integer.prepared statementswith the driver you are using.