SQL repeating data

Hello, this code I’m using seems to just repeat the data for how ever much of the data I have, for example if I have fives rows of data, it will repeat itself 5 times and here is the PHP I’m using:

$dir =			'images/anime_shows/';
$file_display = array('jpg', 'jpeg', 'png', 'gif');


if (file_exists($dir) == false)
{
echo 'Folder \\'', $dir, '\\' not found!';
}
	else
	{
	$dir_contents = scandir($dir);

		foreach ($dir_contents as $file)
		{
		$file_type = strtolower(end(explode('.', $file)));
			
				if ($file !== '.' && $file !== '..' && in_array($file_type, $file_display) == true)
				{
				$animeimg = '<img src="' . $dir . '/' . $file . '" alt="' . $file . '" width="80px;" height="100px" />';
				
				$template->assign_block_vars('anime.img', array(
					'IMG'	=> $animeimg,
					));
					
				$sql = "SELECT name, description FROM phpbb_anime" ;
				$result = $db->sql_query($sql);

				while (($row = $db->sql_fetchrow($result))>0)
				{
					$template->assign_block_vars('anime', array(
						'ANIME_NAME'	=> $row['name'],
						'ANIME_DESC'	=> $row['description'],
					));
				}
				}
		}
	}

Your SQL query is located inside a foreach loop that seems to run for each file you have in a certain directory, but your query doesnt seem to change depending on the file your processing, therefore if you have 5 files the same query will run 5 times.

edit:

and you dont need the >0 on the end of the while statement, PHP while will step through all the elements of the array then stop automatically.

Translation: Query needs a WHERE clause. (and probably an ORDER BY too.)