1

How can I use custom queries.I have a query for my custom module

 $query = "SELECT  * FROM  `XYZ_Productrequest` WHERE  product_sku = '$psku' and email = '$email' ";

I want to customize it as per the magento guideines.Help!
0
$connectionresource = Mage::getSingleton('core/resource');
    $readconnection = $connectionresource->getConnection('core_read');
$sel_qry ="SELECT  * FROM  `XYZ_Productrequest` WHERE  product_sku = '$psku' and email = '$email' ";
$selected = $readconnection->fetchAll($sel_qry);

this is the another way to write query in magento

$connectionresource = Mage::getSingleton('core/resource');
    $readconnection = $connectionresource->getConnection('core_read');

    $allrecord = $readconnection->select()->from(array('tablename'=>'XYZ_Productrequest'))->where('tablenametergallery.product_sku=?', $psku)->where('tablenametergallery.product_email=?', $email);
    $alldata =$readconnection->fetchAll($allrecord);

third way

$product = Mage::getModel('catalog/product')->getCollection()
->addFieldToFilter('sku',$sku);
$order->getSelect()->join(array('yourtablename' => 'yourtablename'), 'main_table.sku=yourtablename.sku',
array('filed1' => 'field1','filed2' => 'filed2'));
8
  • Is this a proper way? Actually I dont want to write whole query. – Vivek Khandelwal Oct 19 '15 at 10:52
  • ok i will give you better query option with magento – Qaisar Satti Oct 19 '15 at 10:57
  • update the answer check it – Qaisar Satti Oct 19 '15 at 11:01
  • Can I have something like this? $collection->addAttributeToFilter( array( array('attribute'=> 'someattribute','like' => 'value'), array('attribute'=> 'otherattribute','like' => 'value'), array('attribute'=> 'anotherattribute','like' => 'value'), ) ); – Vivek Khandelwal Oct 19 '15 at 11:17
  • amitbera.com/… follow this how to create custom collection. – Qaisar Satti Oct 19 '15 at 11:17
0

For converting this type of query, I have to call its model.

$model = Mage::getModel('module_name/model_name')->getCollection()
              ->addFieldToFilter('product_sku' , array ('eq' =>$psku ))
              ->addFieldToFilter('email' , array ('eq' =>$email ))
              ->getData();
print_r($model);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.