Jinandra Jinandra - 4 months ago 31
MySQL Question

Fetching data from table, RewardsPoint Extension: Magento

I am trying to fetch data using this query:[Written in the observer file of RewardPonts extension].

public function salesOrderInvoiceSaveAfter($observer)

echo $id;
$resource = Mage::getSingleton('core/resource');
$readConnection = $resource->getConnection('core_read');
$table = $resource->getTableName('marketplace/saleslist');
$result = $readConnection->fetchCol('SELECT mageproownerid FROM '.$table.'WHERE magerealorderid='.$id.
'AND magebuyerid='.$custom);
$invoice = $observer->getEvent()->getInvoice();
foreach ($invoice->getAllItems() as $item) {
$name = $item->getName();
$type = $item->getSku();
$id = $item->getProductId();
$qty = $item->getQty();
$price = $item->getPrice();
echo $name.",".$type.",".$id.",".$qty.",".$price;

But its not returning any result. Can we use direct sql query inside the extension, if yes then what is wrong with my query?


Yes, You need to debug your code.

$query = 'SELECT mageproownerid FROM '.$table.' WHERE
                               magerealorderid='.$id. ' AND magebuyerid='.$custom;
$result = $readConnection->fetchCol($query);

First check query print output of query then also check in database if it is working then there will be no problem.

I think that you need to put space between ' and where & ' and AND in your query.