Page 1 of 1

Multidimensional arrays issue

Posted: Mon Oct 20, 2003 12:06 pm
by leoden
Hi there can anyone help with this prog.

Its intended function is to build a multidimensional array of file details ( based on selected db record) which is then passed to a mailing function which attaches the aforementioned files to the mail. Everything works fine EXCEPT I only get one entry in my multidimensioned array. The code (please ignore hardcoded values I havent designed an interface yet!)

Code: Select all

while ($row = $salehighlights->fetchrow ())
{ 
$file_array = array($counter=>array("file" => "../Images/Catalogue_Thmbs/365/365lot" . $rowї'LotNo'] . ".jpg", "mimetype" => "image/jpeg", "filename" => "365lot" . $rowї'LotNo'] . ".jpg"));

$message .= "Lot " . $rowї'LotNo'] . " " . $rowї'Decription'] . " SOLD FOR £" . $rowї'HammerPrice'] ."\n\n"  ;
		$counter = $counter + 1;
	}
I do appreciate that the variable $file_array is being cleared out every iteration, but I dont understand how to APPEND the sub arrays into the main array.

Posted: Mon Oct 20, 2003 2:12 pm
by volka
use

Code: Select all

$file_array[] = ...
to append an element to $file_array.
What's the purpose of $counter? if you use

Code: Select all

$file_array = array();
while ($row = $salehighlights->fetchrow ())
{
	$file_array[] = array(
			"file" => "../Images/Catalogue_Thmbs/365/365lot" . $row['LotNo'] . ".jpg",
			"mimetype" => "image/jpeg",
			"filename" => "365lot" . $row['LotNo'] . ".jpg"
		);
}
each key/index of $file_array is equivalent to your $counter-variable

Posted: Mon Oct 20, 2003 3:10 pm
by leoden
Cheers volka that works great.

The reason I used counter was that I copied this code from a mail example the orignal code was

Code: Select all

$file_array = array(0=>array('file'=>'/complete/path/to/myfile.jpg',

'mimetype'=>'image/jpeg',

'filename'=>'myfile.jpg'));
So due to my lack of understanding regarding arrays I thought that everytime the loop iterated the array '$file_array' was being loaded with the new array in position '0' so I whacked a counter in to see if that helps.

I did do alot of searching regarding multidimensional array but all the examples used hard coding rather than dynamic data!