PHP代码显示来自mysql数据库但无法检索id的图像数组

I need to get the id(primary key) of the image clicked by the user but my code to retrieve the image is a while loop

            function displayImage()
            {
                $con = mysqli_connect("localhost","root","programoften");
                mysqli_select_db($con,"tablename");
                $qry = "select * from photos";
                $result = mysqli_query($con, $qry);
                while($row = mysqli_fetch_array($result))
                {
                    echo '<img height="300 width="300" src="data:image;base64,'.$row[9].' ">';
                    echo '<br />';
                }

            }

I'm not quite sure if the code I used to display each image was the most efficient code, so here I am asking for your help guys. Thanks