Código PHP:
   function get_id_cat_ant($id_cat_city)
{
    while ($id_cat_city!=0)
    {
        $query_cat_ant='select id_cat from td_categorias where id_cat='.$id_cat_city;
        $res_cat_ant=mysql_query($query_cat_ant) or die ("Hay error en funcion_cat_ant".mysql_error());
        while($row_cat_ant=mysql_fetch_array($res_cat_ant))
        {
            if ($row_cat_ant['id_cat_ant']==0)
            {
            $city=$row_cat_ant['id_cat'];
            }
            
            $id_cat_city=$row_cat_ant['id_cat_ant'];
        }
    }
    return $city;
} 
     
 



