Dear sneakyimp,
Thank for the reply.
I have given that a try at one point but here is the dilemma. The var_dump($info); of the code using this method lookes like this:
array(1) { [0]=> array(2) { [0]=> array(4) { ["first"]=> string(6) "blah" ["last"]=> string(6) "blah" ["address"]=> string(16) "2512 blah WAY" ["city"]=> string(8) "blah" } [1]=> array(4) { ["first"]=> string(7) "yak" ["last"]=> string(6) "yak" ["address"]=> string(16) "1052 yak AVE" ["city"]=> string(6) "yak" } } }
everyone's address gets glommed into one long array. $info in this case is just an array of one array with a lot of arrays inside it.
now let's say I try to make another array and append that. e.g.:
while ($row = mysql_fetch_array($result)){
$my_array[$i] = array();
$my_array[$i]['first'] = $row['FIRST NAME'];
$my_array[$i]['last'] = $row['LAST NAME'];
$my_array[$i]['address'] = $row['ADDRESS'];
$my_array[$i]['city'] = $row['CITY'];
$my_array2[$i] = array();
$my_array2[$i] = array($my_array);
$i++;
}
$info=array($my_array2);
the var_dump($info); yields:
array(1) { [0]=> array(2) { [0]=> array(1) { [0]=> array(1) { [0]=> array(4) { ["first"]=> string(6) "AMELIA" ["last"]=> string(6) "blah" ["address"]=> string(16) "2512 whatever WAY" ["city"]=> string(8) "nocity" } } } [1]=> array(1) { [0]=> array(2) { [0]=> array(4) { ["first"]=> string(6) "AMELIA" ["last"]=> string(6) "blah" ["address"]=> string(16) "2512 whatever WAY" ["city"]=> string(8) "nocity" } [1]=> array(4) { ["first"]=> string(7) "fake firstP" ["last"]=> string(6) "fake second" ["address"]=> string(16) "1052 main AVE" ["city"]=> string(6) "big city" } } } } }
in this case, the first array repeats, adding the second, then the first and second add a third and so on and so on.
The var_dump($info); that works (hard coded manually) looks like this:
array(3) { [1]=> array(4) { ["line1"]=> string(10) "John Smith" ["line2"]=> string(17) "1000 First Street" ["line3"]=> string(10) "PO Box 123" ["line4"]=> string(17) "Anytown, CA 41000" } [2]=> array(3) { ["line1"]=> string(10) "Bill Gates" ["line2"]=> string(13) "456 Money Way" ["line4"]=> string(17) "Seattle, WA 16456" } [3]=> array(3) { ["line1"]=> string(10) "Steve Jobs" ["line2"]=> string(16) "1 Inifinite Loop" ["line4"]=> string(19) "Cupertino, CA 42389" } }
here, $info has three arrays inside of it. Each array is a seperate row of the database. That is what I need.
Below is my code according to your your suggestions. Anyone's help would be greatly appreciated.
include ('class.label.php');
$labeltype="Av5160";
$label= new Clabel($labeltype);
// db connection
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);
$SQL = "SELECT * FROM mailinglist";
$result = mysql_query($SQL) or die(mysql_error());
$row = mysql_fetch_array($result);
$i=0;
while ($row = mysql_fetch_array($result)){
$my_array[$i] = array();
$my_array[$i]['first'] = $row['FIRST NAME'];
$my_array[$i]['last'] = $row['LAST NAME'];
$my_array[$i]['address'] = $row['ADDRESS'];
$my_array[$i]['city'] = $row['CITY'];
$i++;
}
$info=array($my_array);
var_dump($info);
//$label->makeLabel($info);
?>