piyush23424 Posted November 25, 2010 Share Posted November 25, 2010 Hi, I am working on creating excel sheet with php but i am getting difficulites in inserting dynamic array in the main array. Main array starts from $sheet1. The first array inside the main array are heading of the excel sheet. and the array having values like tes1, test2 etc are the values of excel sheet. If i use the static values then it works fine. but i want to make it dynamic with database values(see the while loop). Pls help me to insert the array created by while at the place of test values array. Thanks while($row = mysql_fetch_array($res)) { array("test","test1", "test2","test4", "test5", "test6", "test7","test8","test9"); } //print_r($string); //$string = implode(",",$string); $sheet1 = array( array('Customer\´s Name','Customer E-mail Address','Customer Address 1','Customer Address 2','Billing City Name', 'Customer\´s Billing State', 'Customer\´s Postal Code', 'Country', 'Customer´s Phone Number'), array("test","test1", "test2","test4", "test5", "test6", "test7","test8","test9"), array("test","test1", "test2","test4", "test5", "test6", "test7","test8","test9"), array("test","test1", "test2","test4", "test5", "test6", "test7","test8","test9"), array("test","test1", "test2","test4", "test5", "test6", "test7","test8","test9"), ); Quote Link to comment Share on other sites More sharing options...
piyush23424 Posted November 25, 2010 Author Share Posted November 25, 2010 Hi, I am working on creating excel sheet with php but i am getting difficulites in inserting dynamic array in the main array. Main array starts from $sheet1. The first array inside the main array are heading of the excel sheet. and the array having values like tes1, test2 etc are the values of excel sheet. If i use the static values then it works fine. but i want to make it dynamic with database values(see the while loop). Pls help me to insert the array created by while at the place of test values array. Thanks while($row = mysql_fetch_array($res)) { array("test","test1", "test2","test4", "test5", "test6", "test7","test8","test9"); } //print_r($string); //$string = implode(",",$string); $sheet1 = array( array('Customer\´s Name','Customer E-mail Address','Customer Address 1','Customer Address 2','Billing City Name', 'Customer\´s Billing State', 'Customer\´s Postal Code', 'Country', 'Customer´s Phone Number'), array("test","test1", "test2","test4", "test5", "test6", "test7","test8","test9"), array("test","test1", "test2","test4", "test5", "test6", "test7","test8","test9"), array("test","test1", "test2","test4", "test5", "test6", "test7","test8","test9"), array("test","test1", "test2","test4", "test5", "test6", "test7","test8","test9"), ); I want to replace the static array with dynamic array created by while loop. Quote Link to comment Share on other sites More sharing options...
BLaZuRE Posted November 25, 2010 Share Posted November 25, 2010 I'm assuming you already know how to connect/disconnect and query a database. If you want your array to appear under $sheet1, you'll have to loop after you create the first array. Try something like $sheetArray[0] = array('Customer\´s Name','Customer E-mail Address','Customer Address 1','Customer Address 2','Billing City Name', 'Customer\´s Billing State', 'Customer\´s Postal Code', 'Country', 'Customer´s Phone Number'); $count = 1; while($row = mysql_fetch_array($res)) { $sheetArray[$count] = array($row['fieldname1'], $row['fieldname2'], ... ); ++$count; } where fieldnameX are your fieldnames in your database. Quote Link to comment Share on other sites More sharing options...
piyush23424 Posted November 25, 2010 Author Share Posted November 25, 2010 I'm assuming you already know how to connect/disconnect and query a database. If you want your array to appear under $sheet1, you'll have to loop after you create the first array. Try something like $sheetArray[0] = array('Customer\´s Name','Customer E-mail Address','Customer Address 1','Customer Address 2','Billing City Name', 'Customer\´s Billing State', 'Customer\´s Postal Code', 'Country', 'Customer´s Phone Number'); $count = 1; while($row = mysql_fetch_array($res)) { $sheetArray[$count] = array($row['fieldname1'], $row['fieldname2'], ... ); ++$count; } where fieldnameX are your fieldnames in your database. Thanks BLaZuRE, your suggestion Worked for me . i was working on this problem from last 3 hours and you just solved it in seconds....Thanks again... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.