Danny620 Posted September 10, 2012 Share Posted September 10, 2012 Hi i need to create an array like $activation_code_array = array( array('Pet ID' => '12221', 'Activation Code' => '1001'), array('Pet ID' => '1221', 'Activation Code' => '1002'), array('Pet ID' => '12213', 'Activation Code' => '1004') ); function generate_activation_code($dbc, $qty) { $activation_code_array = array(); // Store activation codes in array $count = 0; while ($qty > $count) { usleep(70076); $activation_code = strtoupper(substr(md5($count . microtime()), -); // Make sure the activation code is unique: $q = "SELECT pet_id FROM pet WHERE activation_code='$activation_code'"; $r = mysqli_query ($dbc, $q); // Get the number of rows returned: $rows = mysqli_num_rows($r); if ($rows == 0) { // No problems! $activation_code_array[$count] = array('Pet ID' => $count, 'Activation Code' => $activation_code); } $count++; } return $activation_code_array; } Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 10, 2012 Share Posted September 10, 2012 Okay? Quote Link to comment Share on other sites More sharing options...
Danny620 Posted September 10, 2012 Author Share Posted September 10, 2012 i need to export it into excel thats why i need the array like this one to do it include('data_export_helper.class.inc.php'); header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename=users.xls"); $users = array( array('username' => 'bob', 'email' => 'bob@bob.com'), array('username' => 'carl', 'email' => 'carl@internet.com'), array('username' => 'wide_load', 'email' => 'widey@load.com') ); $export = new data_export_helper($users); $export->set_mode(data_export_helper::EXPORT_AS_EXCEL); $export->export($result); echo $result; Quote Link to comment Share on other sites More sharing options...
Monkuar Posted September 10, 2012 Share Posted September 10, 2012 Not to be rude and I admit, I am not the smartest or talented user here. But, Is it me or am I completely confused on what you're trying to do? If you need some type of help, you need to give us code and explain it and show us what it's NOT doing that you WANT it to do. you just cannot throw a whole bunch of code and tell us "fix it". Post errors/etc... Quote Link to comment Share on other sites More sharing options...
Danny620 Posted September 10, 2012 Author Share Posted September 10, 2012 haha sorry its a bit late at night for me, what i need to achieve is i want to be able to export that array of data into an excel spreadsheet like Pet ID | Activation Code 1001 | 7HSUSJWW 1002 | 7SSAAWXA So i bought a php class that needs the array in this format to be able to do it however i dont know how to do it in my previous code include('data_export_helper.class.inc.php'); header("Content-Type: application/octet-stream"); header("Content-Disposition: attachment; filename=users.xls"); $users = array( array('username' => 'bob', 'email' => 'bob@bob.com'), array('username' => 'carl', 'email' => 'carl@internet.com'), array('username' => 'wide_load', 'email' => 'widey@load.com') ); $export = new data_export_helper($users); $export->set_mode(data_export_helper::EXPORT_AS_EXCEL); $export->export($result); echo $result; Quote Link to comment Share on other sites More sharing options...
Jessica Posted September 11, 2012 Share Posted September 11, 2012 If you paid for code, and not for support, that was money down the drain. Quote Link to comment Share on other sites More sharing options...
Danny620 Posted September 11, 2012 Author Share Posted September 11, 2012 would you be so kind and show me how to save array as excel file? Quote Link to comment Share on other sites More sharing options...
Christian F. Posted September 11, 2012 Share Posted September 11, 2012 Even if we wanted to, we cannot help you. Simply because we do not know the data_export_helper class is written. Also, how to save it as an "Excel" file really depends upon what version of the XLS format you want to have it in. My best recommendation is to export the data as a CSV file, and then import that into Excel: Let Excel itself sort out its proprietary format. 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.