dqjcb132285 2014-03-28 12:06
浏览 55
已采纳

too long

I am developing a module and I've now come to a point where I want to query a database table i added to the Magento database

I want to query the table looking for a specific value and it works. it finds the correct row but what I want to do is use any of the values in the array

My table structure

CREATE TABLE `salesrule_coupon_facebook` (
  `entity_id` int(10) NOT NULL AUTO_INCREMENT,
  `facebook_id` int(10) DEFAULT NULL,
  `code` varchar(255) CHARACTER SET utf16 DEFAULT NULL,
  PRIMARY KEY (`entity_id`)
)

My resource model

<?php

class MyModule_Facebook_Model_Resource_Facebookcoupon extends Mage_Core_Model_Resource_Db_Abstract
{
    protected function _construct()
    {
        $this->_init('facebook/facebookcoupon', 'entity_id');
        $this->_storeId = (int)Mage::app()->getStore()->getId();
    }

    public function getData($code)
    {
        $resource = Mage::getSingleton('core/resource');
        $select = $resource->getConnection('core_read')->select();
        $select
            ->from($this->getTable('facebook/facebookcoupon'))
            ->where('code = :code');

        $result = $resource->getConnection('core_read')->fetchAll($select, array('code' => $code));

        return $result;
    }
}

and the block that queries the database

<?php

class MyModule_Facebook_Block_Content extends Mage_Core_Block_Template
{
    private $couponCode;

    public function checkFacebookId()
    {
        $model = Mage::getResourceModel('facebook/facebookcoupon')->getData('AXM-1547-4518-9884');

        var_dump($model);

    }

This is the output from the block class

array(1) { [0]=> array(3) { ["entity_id"]=> string(1) "1" ["facebook_id"]=> string(8) "14547854" ["code"]=> string(18) "AXM-1547-4518-9884" } }

How do a use an element in that array so i can make comparisons etc if needed or even just print an element?

  • 写回答

1条回答 默认 最新

  • duanmao7553 2014-03-28 14:47
    关注

    Managed to fix it myself like this

    $model = Mage::getResourceModel('facebook/facebookcoupon')->queryData('AXM-1547-4518-9884');
    
    foreach($model as $row) {
        echo $row['code'];
    } 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?