DEATHMETALGORE

Using mbinettes query

Dec 31st, 2012
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.18 KB | None | 0 0
  1. // First I created a method using mbinettes help:
  2. public function get_id_by_name($image_name_ary)
  3. {
  4.     global $db;
  5.    
  6.     $user_info_ary  = array();
  7.     $image_name_ary = (is_array($image_name_ary)) ? $image_name_ary : array($image_name_ary);
  8.     $image_name_str = "'" . implode("', '", $image_name_ary) . "'";
  9.        
  10.     $sql = "SELECT img.user_id, image_name, username  
  11.         FROM imgit_images img
  12.         INNER JOIN imgit_users u ON u.id = img.user_id
  13.         WHERE image_name IN (" . $image_name_str . ")";
  14.     $query = $db->prepare($sql);
  15.     $query->execute();
  16.        
  17.     $row = $query->fetchAll(PDO::FETCH_ASSOC);
  18.        
  19.     return $row;
  20. }
  21.  
  22. // This got me an array with all results I needed - THE BIG PART
  23. // Then I started looping on my $images array which has the scandir(); function
  24. // Inside this loop, I did another FOR loop to finish the work.
  25. // In the end it looked like this:
  26. $images     = scandir('i');
  27. $user_inf   = $admin->get_id_by_name($images);
  28.  
  29. foreach ($images as $i => $img)
  30. {
  31.     echo $img; // Just echoing even if it doesn't belong to an user.
  32.    
  33.     for ($i = 0; $i < sizeof($user_inf); $i++)
  34.     {
  35.         if ($img == $user_inf[$i]['image_name'])
  36.         {
  37.             echo '<br /><br />By', $user_inf[$i]['username'];
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment