0

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

Edited by Nick Evan: Fixed formatting

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by saiprem
0

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.

0

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.

Edited by Nick Evan: Fixed formatting

0

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>";
		}
	}
}

Edited by saiprem: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.