Hi guys,

I have written this code that will convert the images in Path1 to thumbs and will copy it to Path2. In the image folder there are more than 100 images. However this code will convert the first 5 images and will stops!

If I remove the "createThumb" part of the code and only echo the file names, it will work great. I also used the "foreach" rather than "for" loop still the same problem!
Anyone with any help or idea greatly appreciated…

<?php        
$h = 75;
$w = 125;
$path1 = ($rootpath.'images/');
$path2 = ($rootpath.'images/thumb/');

$sql = "SELECT `pic` FROM `album`";
$sql_result = mysql_query($sql);
$num_rows = mysql_num_rows($sql_result);    

for ($i=0; $i <= $num_rows -1; $i++) {

$row = mysql_fetch_array($sql_result);
$filename = $row['pic'];

if(createThumb($filename, $w, $h, $path1, $path2, $filename)) {

echo "Created Thumb: $filename <br>";
    }
}       
?>

Thanks,

Steve

May I know what is the value you are getting from the variable $num_rows,

Try to echo each step in your for loop with breaking a line. You will find your solution where it is failing.

I took off the $numrows (thanks) and added the $i to the echo. Is this what you mean for echoing the for loop?

the code is like this now:

<?php        
$h = 75;
$w = 125;
$path1 = ($rootpath.'images/');
$path2 = ($rootpath.'images/thumb/');

$sql = "SELECT `pic` FROM `album`";
$sql_result = mysql_query($sql);

for ($i=0; $i <= $sql_result -1; $i++) {

$row = mysql_fetch_array($sql_result);
$filename = $row['pic'];

if(createThumb($filename, $w, $h, $path1, $path2, $filename)) {

echo "$i - Created Thumb: $filename <br>";
    }
}       
?>

As before it shows that it stops after the fifth record.

I took off the $numrows (thanks) and added the $i to the echo. Is this what you mean for echoing the for loop?

the code is like this now:

<?php
$h = 75;
$w = 125;
$path1 = ($rootpath.'images/');
$path2 = ($rootpath.'images/thumb/');

$sql = "SELECT `pic` FROM `album`";
$sql_result = mysql_query($sql);

for ($i=0; $i <= $sql_result -1; $i++) {

$row = mysql_fetch_array($sql_result);
$filename = $row;

if(createThumb($filename, $w, $h, $path1, $path2, $filename)) {

echo "$i - Created Thumb: $filename <br>";
}
}
?>

As before it shows that it stops after the fifth record.

Hi stockvale,
I didn't ask you to remove $num_rows, the previous code which you were having was correct, I just asked what value you are getting for $num_rows, and I asked you to echo and check where the script is failing, Ok leave about it and try the following code... I hope it will works for you.

$h = 75;
$w = 125;
$path1 = ($rootpath.'images/');
$path2 = ($rootpath.'images/thumb/');

$sql = "SELECT `pic` FROM `album`";
$sql_result = mysql_query($sql);
$num_rows = mysql_num_rows($sql_result);

if($num_rows > 0)
{
	while($row = mysql_fetch_assoc($sql_result))
	{
		$filename = $row['pic'];
		if(createThumb($filename, $w, $h, $path1, $path2, $filename)) // Can I know why are you passing $filename 2 times for this function....
		{
			echo "Created Thumb: $filename <br>";
		}
	}
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.