mysql - Looping through folder of images and also select query of names using PHP to display in HTML list item -


this question has answer here:

i have folder of images , database containing list of names. attempting loop through folder , names simultaneously , display both outputs in list item.

<ul>     <?php        $names_query = "select name people";        $names_results = mysqli_query($con, $names_query);          $dir = "images/people/";        $opendir = opendir($dir);        while (mysqli_fetch_array($names_results) && ($file = readdir($opendir)) !== false) {     ?>       <li>       <?php           if ($file != "." && $file != "..") {             echo $names["name"];             echo "<img class=" . "people" . " src='$dir/$file'/>";           }       ?>       </li>       <?php }       ?> </ul> 

this displays images in folder, not "name" corresponding each image obtained mysql query. also, if statement should not display image or name when files "." or ".." not appear working there space 12 images when there should 10 displayed.

edit

thank feedback. i've incorporated edits code i'm still having 1 problem echoing names fetched array. when runs first "name" echoed each of images.

<ul>    <?php      $names_query = "select name people";      $names_results = mysqli_query($con, $names_query);      $names = mysqli_fetch_array($names_results);      $dir = "images/people/";      $opendir = opendir($dir);      while ($names && ($file = readdir($opendir)) !== false) {          if ($file != "." && $file != "..") {    ?>      <li>         <?php            echo $names["name"];            echo "<img class=" . "people" . " src='$dir/$file'/>";         ?>      </li>      <?php          }       }       ?>   </ul> 

i apologise if question duplicate , if mistakes stupid i've been teaching myself php , mysql 2 weeks appreciate patience helping clueless noob.

you should fetch $names_results $names variable.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -