Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // First I created a method using mbinettes help:
- public function get_id_by_name($image_name_ary)
- {
- global $db;
- $user_info_ary = array();
- $image_name_ary = (is_array($image_name_ary)) ? $image_name_ary : array($image_name_ary);
- $image_name_str = "'" . implode("', '", $image_name_ary) . "'";
- $sql = "SELECT img.user_id, image_name, username
- FROM imgit_images img
- INNER JOIN imgit_users u ON u.id = img.user_id
- WHERE image_name IN (" . $image_name_str . ")";
- $query = $db->prepare($sql);
- $query->execute();
- $row = $query->fetchAll(PDO::FETCH_ASSOC);
- return $row;
- }
- // This got me an array with all results I needed - THE BIG PART
- // Then I started looping on my $images array which has the scandir(); function
- // Inside this loop, I did another FOR loop to finish the work.
- // In the end it looked like this:
- $images = scandir('i');
- $user_inf = $admin->get_id_by_name($images);
- foreach ($images as $i => $img)
- {
- echo $img; // Just echoing even if it doesn't belong to an user.
- for ($i = 0; $i < sizeof($user_inf); $i++)
- {
- if ($img == $user_inf[$i]['image_name'])
- {
- echo '<br /><br />By', $user_inf[$i]['username'];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment