Try this :
<?php
$current_cat = null;
$data[]=null;
while($row = mysql_fetch_assoc($categories))
{
$data[] = $row;
}
foreach($data as $item)
{
if ($item["title"] != $current_cat)
{
$current_cat = $item["title"];
echo $current_cat;
}
else
{
echo $item["title"];
}
}
?>