Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Grabbing Emails of Customers
 
dcburkejr
Jr. Member
 
Total Posts:  4
Joined:  2012-09-06
 

I am grabbing customers emails that have bought a specific product. Here is the code i have:

<?php
$data = Mage::getSingleton('core/resource') ->getConnection('core_read')->fetchAll("SELECT order_id FROM sales_flat_order_item WHERE sku='PRODUCT-SKu-HERE'");
foreach ($data as $v) {
foreach ($v as $p) {
echo $p;
$data2 = Mage::getSingleton('core/resource') ->getConnection('core_read')->fetchAll("SELECT customer_email FROM sales_flat_order WHERE entity_id='".$p."'");
}
}
print_r($data2);
?>

I cannot get it to work right at this point, (I only get the last email in the list).

 
Magento Community Magento Community
Magento Community
Magento Community
 
kab8609
Moderator
 
Avatar
Total Posts:  821
Joined:  2009-04-07
Cleveland
 

Quickly looking at it, you need to make it an array and have it add to the array.

<?php 
$data 
Mage::getSingleton('core/resource') ->getConnection('core_read')->fetchAll("SELECT order_id FROM sales_flat_order_item WHERE sku='PRODUCT-SKU-HERE'"); 
$data2 = array();
foreach (
$data as $v
foreach ($v as $p

$data2[] 
Mage::getSingleton('core/resource') ->getConnection('core_read')->fetchAll("SELECT customer_email FROM sales_flat_order WHERE entity_id='".$p."'"); 


print_r
($data2); 
?>

Another example here: http://stackoverflow.com/questions/3045619/need-to-store-values-from-foreach-loop-into-array

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top