def order_synapses_by_section_number(cur,stype='chemical'):
    """
    Returns synapses ordered by section number. Row format
    [pre,post,sections,mid obj,continNum,IMG_Number,IMG_SectionNumber,X,Y]
    
    Parameters
    ----------
    cur : MySQLdb cursor
    stype : str
      synapse type : 'chemical' or 'electrical'

    """

    sql = ("select pre,post,sections,mid,continNum,"
           "object.IMG_Number,image.IMG_SectionNumber, "
           "object.OBJ_X,object.OBJ_Y "
           "from synapsecombined "
           "join object on synapsecombined.mid = object.OBJ_Name "
           "join image on image.IMG_Number = object.IMG_Number "
           "where synapsecombined.type = '%s' "
           "order by image.IMG_SectionNumber"
           %stype)
    cur.execute(sql)
    return cur.fetchall()