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?
Managed to fix it myself like this