image gallery with filter by year from mysql database

I have a mysql table of images with columns Heading, Year and Image_link. Years are in YYYY format like 1988, 1992, 1994,1995, 1999, 2013 etc (Not serially all years are there..random are..)

I want to display images with year-wise buttons and one button for All. I mean When All is clicked, All images will be shown.. If specific year button is clicked, images with that year should be shown...

I googled for it and I got Portfolio Image Gallery, But examples were with static data. I couldn't find mysql php examples for the same.

I tried it with group by mysql_query but some how I could not make it.

data is fetched from mysql with no problem.. I am stuck How to create yearwise filter buttons and display images related to that year.

Your help is appreciated.

Present non-working code is as follows as I got stuck here How to work on it.......

<?php
$query = "select * from image_table group by year  order by year asc";
$numrows = $database->num_rows($query); // wrapper class is used               
  if($numrows !=0){
     $result = $database->get_results($query);  // wrapper class is used
       foreach($result as $data){
          $year = $data['year'];
?>
    <div align="center">
        <button class="btn btn-default filter-button" data-filter="all">All</button>
        <button class="btn btn-default filter-button" data-filter="<?php echo $year;?>"><?php echo $year;?></button>

    </div>
    <br/>



        <div class="gallery_product col-lg-4 col-md-4 col-sm-4 col-xs-6 filter <?php echo $data['year'];?>">
            <img src="url_for_image_from_mysql_row" class="img-responsive">
        </div>

<?php } } ?>