Jump to content

Multidimensional Arrays While Lopp


Danny620

Recommended Posts

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

 

 

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

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...

 

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.