无法在for循环中添加链接

I am tryig to make a photo gallery on my website. I have a small problem with making link on images I have in for loop

Since You requested full code here it is:

<html>
<head>
    <meta charset="UTF-8">
    <title>Fotečky</title>
    <style>
        .foto{
            position: relative;
            display: inline-block;
            text-align: center;
            width: 200px;
            border: solid;
            margin-left: 6%;
        }
        #date{
            position: relative;
            text-align: center;
            width: 200px;
        }
        a { color: #000000; text-decoration: none; }
        .menu { 
            background-color: #FF9933;
            height: 10%;
            line-height: 300%;
        }
    </style>
</head>
<body>

    <div class="menu">
        <a href="insert.php"><center><h2>Upload photo</h2></center></a>
    </div>
    <br>

    <?php

            mb_internal_encoding("UTF-8");

            $connect = mysql_connect("","","") or die("Couldn't connect");
            mysql_set_charset('utf8',$connect);
            mysql_select_db("") or die("Couldn't find db");

            $SQLCommand = "SELECT * FROM foto";
            $result1 = mysql_query($SQLCommand); $database = array(); $index = 1; // make a new array to hold all your data
            while($row1 = mysql_fetch_assoc($result1)) // loop to give you the data in an associative array so you can use it however.
            {
                $database[$index] = $row1;

                $index++;
            }


            for ($i=1; $i < count($database); $i++) {
                echo '<a href="photo.php?id='.$database[$i]['id'].'">';
                echo '<div class="foto">';
                echo '<img title="'.$database[$i]['description'].'" alt="'.$database[$i]['description'].'" src="data:image/jpg/png/jpeg;base64,'.base64_encode( $database[$i]['image'] ).'" width="200px"/>';
                echo "<div id='date'>".$database[$i]['uploaded']."</div>";
                echo '</div>';
                echo '</a>';

                if ((($i % 4) == 0) && ($i != 0)) {
                    echo '<br><br>';
                }
            }
    ?>

</body>

I want to display image one by one and be able to click on them -> link that brings me to photo.php?id= with id of that image. (id is from 1 to n)

db sructure: enter image description here