Magento 1.7 – How to Retrieve Values from Database by Fieldname

adminmagento-1.7module

I have a custom table in my database with three fields ie id a_id and cat_id

I have an entry like this in the table.

    id a_id c_id

    2   7   7
    3   7   8
    4   7   8
    5   7   8
    6   7   5
    7   7   5
    9   9   7
    10  9   5
    11  7   5

Now I want to fetch data according to an a_id so that all the values will be collect in an array.

I tried this

 $categoryModel= Mage::getModel('blog/category')
        ->getCollection()
        ->addFieldToFilter('a_id','7'); 

but this shows an array without any value in it.

I want to update the table with the form so when I use this code

$categoryModel= Mage::getModel('blog/category')->load('7');

it only shows the last value of the table.

and when I collect this in an array again it only shows the last value.

So how can I collect all the value of the a_id = 7 in one array.

Here is my model file

class Vertax_Blog_Model_Mysql4_Category extends Mage_Core_Model_Mysql4_Abstract
{
 public function _construct()
 {
  $this->_init('blog/category','id');
 }
}
?>

Best Answer

Are you sure you get data correctly from collection?

It should be like this

 $categoryCollection = Mage::getModel('blog/category')
    ->getCollection()
    ->addFieldToFilter('a_id','7');
foreach ($categoryCollection as $categoryModel) {
    //row data will be here
    $categoryData = $categoryModel->getData();
}