php - 从表中获取数据,RewardsPoint 扩展 : Magento

标签 php mysql magento

我正在尝试使用此查询获取数据:[写在 RewardPonts 扩展的观察者文件中]。

public function salesOrderInvoiceSaveAfter($observer)
{


$id=$observer['invoice']->getOrder()->getRealOrderId();
  echo $id;
  $custom=$observer['invoice']->getOrder()->getCustomerId();
  $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);
      var_dump($result);
  $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; 
  }

但是它没有返回任何结果。我们可以在扩展中使用直接的 sql 查询吗?如果可以,那么我的查询有什么问题?

最佳答案

是的,您需要调试您的代码。

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

首先检查查询的打印输出,然后检查数据库是否正常,那么就没有问题。

我认为您需要在查询中的 ' 和 where & ' 和 AND 之间放置空格。

关于php - 从表中获取数据,RewardsPoint 扩展 : Magento,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27289845/

相关文章:

javascript - 如何使用AJAX、PHP和MySQL实时发出通知?

PHP 函数不适用于 javascript

javascript - 带有图表的数据表查询

mysql - 在MySQL看来,是用union开始更快还是用union结束更快呢?

mysql - 在 Joomla 中更新数据库的多行和多列

Magento 1.12 和 Solr 3.6 没有正确的结果,也没有拼写建议

php - 从php更新数据库信息,而不是保存

mysql - 随机执行 SELECT 时为数据库表建立索引会有多大区别

php - Magento 覆盖核心模型

mysql - Magento 从数据库转储中导出产品、类别