samedi 26 octobre 2019

How to use if ..else condition to select folder in PHP

I have tried the code below to select images from different folders using the if...else statement

 $username=$_SESSION['username'];
 $db = mysqli_connect('localhost', 'root', '', 'registrations');

 $selectlevels="SELECT level from users WHERE username='$username'";
 $getlevels=mysqli_query($db,$selectlevels);

 while($lvls=mysqli_fetch_array($getlevels)){

 if ($lvls['level']=='1') {
 $dire="Annotated Dataset/images1/";
 $images = glob($dire. '*.{jpg,jpeg}', GLOB_BRACE);

 shuffle($images);
 $images=array_slice($images,0,6);

 return $images;
 }

 else{
  $dire="Annotated Dataset/images/";
  $images = glob($dire. '*.{jpg,jpeg}', GLOB_BRACE);

 shuffle($images);
 $images=array_slice($images,0,6); 
 return $images;
  }

  $_SESSION['images']=$images;
  }

The $_SESSION['images'] is used in the later code.

When i tried to execute my code, I could not fetch the folders. and in console, there are no errors. I checked the queries, it works perfect. I think, i did something wrong with the if else statement. Can someone help me out with this problems.

Aucun commentaire:

Enregistrer un commentaire