How to for loop an image name based on user : <p>I'm trying to for loop the name of the photo in my database based on the username</p>

<pre><code>&lt;?php
        $sql = "SELECT Name FROM images
        WHERE user=$user";      
        $result = mysqli_query($con, $sql);

        $name = $row['Name'];



        // loop through the array of files and print them all in a list
        for($index=0; $index &lt; $indexCount; $index++) {
            $extension = substr($dirArray[$index], -3);
            if ($extension == 'jpg'){ // list only jpgs
                echo '&lt;div class="container22"&gt;&lt;img class="testing2 img-thumbnail" src="users/userimg/'.$name.'' . $dirArray[$index] . '" alt="Image" /&gt;&lt;/div&gt;'; 
            }   
        }

        ?&gt;
</code></pre>
