I would like to export the last 1000 orders with following fields: order id, customer email, first name, last name.

Is there an easy way to export a CSV like this? I do have access to PHPMyAdmin.

2 Answers 2


Here is the script to export last 1000 orders into csv format. To use this script just create test.php in your magento root directory and paste this code and run this script.

ini_set('display_errors', 1);

$orders = Mage::getModel('sales/order')->getCollection()
    ->setOrder('created_at', 'desc')
    ->setPageSize(1000); // from here you can update the order count
$fp = fopen(Mage::getBaseDir() . DS . "exports_order.csv", "w+");
$csvHeader = array('Order ID', 'Customer Email', 'Customer First Name', 'Customer Last Name');
fputcsv($fp, $csvHeader, ",");
foreach ($orders as $order) {
    fputcsv($fp, array(

echo 'exports_order.csv Successfully created.';

Use "Export" function to export to CSV table sales_flat_order.

  • 1
    For some reason the sales_flat_order table is missing the last orders that I see in the backend. For example the last order in the BE is: 100002988 and the last entity_id in "sales_flat_orders" is 2772.. entity_id is the order ID right ? Commented Jan 20, 2018 at 20:30
  • 2
    entity_id is not the same thing as order number. entity_id is just database table index, autoincrement number, and increment_id is your "human" order number, both visible for customer and in admin panel. Commented Jan 20, 2018 at 20:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.