-2

I'm trying to for loop the name of the photo in my database based on the username

<?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 < $indexCount; $index++) {
            $extension = substr($dirArray[$index], -3);
            if ($extension == 'jpg'){ // list only jpgs
                echo '<div class="container22"><img class="testing2 img-thumbnail" src="users/userimg/'.$name.'' . $dirArray[$index] . '" alt="Image" /></div>'; 
            }   
        }

        ?>
  • 2
    ok... and the problem/question is what exactly? – Funk Forty Niner Apr 18 '16 at 14:21
  • 3
    oh and you do realize that you most likely need to quote that value in your query and you're not checking for errors. – Funk Forty Niner Apr 18 '16 at 14:21
  • And you should use prepared statement instead of directly printing your variable in your query – lisa Apr 18 '16 at 14:23
  • 1
    Either you are not showing all the real code or there are a number of variables that have just been invented out of thin air. Show all code or all we can do is **guess** and we wont stay around doing that for long. Please read [What topics can I ask about](http://stackoverflow.com/help/on-topic) and [How to ask a good question](http://stackoverflow.com/help/how-to-ask) And [the perfect question](http://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/) – RiggsFolly Apr 18 '16 at 14:26
  • Where are you reading the resultset generated by that query? i.e. some sort of `mysqli_fetch_????()` – RiggsFolly Apr 18 '16 at 14:43

1 Answers1

-1

I dont know what exactly is your problem but you can loop on a string in PHP and refer to the string as array

$str = "abcd";
for($i = 0; $i < strlen($str); $i++){
    echo $str[$i] ."<br/>";
}

Output is a b c d

zion ben yacov
  • 715
  • 6
  • 13