Query problems?

I’m trying to get the query to show all of the rows, but all its doing is just duplicating the first row of data.

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" />';
		
		$sql = "SELECT image, name, description FROM phpbb_anime";
		$result = $db->sql_query($sql);
		$row = $db->sql_fetchrow($result);
		while ($numrow = mysql_fetch_array($result)) {
			$animename = $row['name'];
			$animedesc = $row['description'];
			$animeimg = $row['image'];
			}
		
		$template->assign_block_vars('anime', array(
			'ANIME_NAME'   		=> $row['name'],
			'ANIME_DESC' 		=> $row['description'],
			'ANIME_IMG'			=> $animeimg,
			
		   ));
	}
}
}

Try this:

http://php.net/manual/en/function.mysql-fetch-array.php




<?php
mysql_connect("localhost", "mysql_user", "mysql_password") or
    die("Could not connect: " . mysql_error());
mysql_select_db("mydb");

$result = mysql_query("SELECT id, name FROM mytable");

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
    printf("ID: %s  Name: %s", $row[0], $row[1]);
}

mysql_free_result($result);
?


Try this…

while ($numrow = mysql_fetch_array($result)) {
$animename = $numrow[‘name’];
$animedesc = $numrow[‘description’];
$animeimg = $numrow[‘image’];
}

Or you can try this:

<?php
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" />';
	        
			$sql = "SELECT image, name, description FROM phpbb_anime";
			$result = $db->sql_query($sql);
			
			while ( $row = mysql_fetch_assoc($result)) {
				$animename 	= $row['name'];
				$animedesc 	= $row['description'];
				$animeimg 	= $row['image'];
			}
			
			$template->assign_block_vars('anime', array(
				'ANIME_NAME'	=> $row['name'],
				'ANIME_DESC'	=> $row['description'],
				'ANIME_IMG'	=> $animeimg,
			));
		}
	}
}  

I probably should have mentioned that I’m getting the error “mysql_fetch_assoc() expects parameter 1 to be resource, object given”

Can i see the $db class you are using? mysql_fetch_assoc and mysql_fetch_array only work with the mysql_connect method. Unless the $db class uses that as the base connection method, you may need to switch to that instead of you db class if you want to use mysql_fetch_array or mysql_fetch_assoc.

Not sure if you need to use the db class but this should work:

	$conn = mysql_connect( HOST, USERNAME, PASSWORD );
	mysql_select_db( DBNAME );
	
    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" />';

    			$sql = "SELECT image, name, description FROM phpbb_anime";
    			$result = mysql_query( $sql, $conn );

    			while ( $row = mysql_fetch_assoc($result)) {
    				$animename 	= $row['name'];
    				$animedesc 	= $row['description'];
    				$animeimg 	= $row['image'];
    			}

    			$template->assign_block_vars('anime', array(
    				'ANIME_NAME'	=> $row['name'],
    				'ANIME_DESC'	=> $row['description'],
    				'ANIME_IMG'	=> $animeimg,
    			));
    		}
    	}
    }

The thing is, I’m not sure what $db is composed of, because I’m using phpbb, so I’m not sure from which file it originates from.

Edit: I tried what devildoc34 said, and that didn’t work either.

Not sure about how the db class works but from looking it up you can use the $db->sql_fetchrow() to get the row contents instead of using mysql_fetch_assoc.

Ok, the error went away, but so did all my data, and the images I had displayed just turn into file paths, with the same paths 3 times.