I'm taking a shot in the dark with the names here but this should work
$query = "SELECT g.filename filename, g.id id, g.date date,
g.category category, g.imagetext imagetext,
DATE_FORMAT(g.date,'%a, %D %M, %Y') as readdate,
DATE_FORMAT(g.date,'%H:%i') as time,
c.imageID imageID, c.date date
FROM $TableName g, GalleryComments c
WHERE g.username='".$username."'
AND c.imageID=g.id
AND c.imageID > 0
GROUP BY g.id
ORDER BY g.date DESC, c.date DESC";
if that one doesnt work try this one
$query = "SELECT g.filename filename, g.id id, g.date date,
g.category category, g.imagetext imagetext,
DATE_FORMAT(g.date,'%a, %D %M, %Y') as readdate,
DATE_FORMAT(g.date,'%H:%i') as time,
c.imageID imageID, c.date date
FROM $TableName g, GalleryComments c
WHERE g.username='".$username."'
AND c.imageID=g.id
AND c.imageID > 0
GROUP BY g.id
ORDER BY c.date DESC, g.date DESC";