1

I try to retrieve some data using magento select. Below is my coding.

Mage::app('default');
    $connection = Mage::getSingleton('core/resource')->getConnection('core_read');
    $select = $connection->select()
                ->from('wired_points', array('*')) 
                ->where('order_id=?',$orderID);   

    //$rowsArray = $connection->fetchAll($select); // return all rows
    $rowArray =$connection->fetchRow($select);   //return rowe

I want to add one more condition in where like log_id.

How can i add the second parameter to my where clause?

3 Answers 3

2
$select = $connection->select()
                ->from('wired_points', array('*')) 
                ->where('order_id=?',$orderID)
                ->where('log_id=?',$logId);
0
2

If you want to add other with and condition then you can use below code:

$select = $connection->select()
            ->from('wired_points', array('*'))
            ->where('order_id=?',$orderID)
            ->where('log_id=?',$logId);

If you want to add "OR condition" then you can use below code:

$select = $connection->select()
            ->from('wired_points', array('*'))
            ->where('order_id=?',$orderID)
            ->orWhere('log_id=?',$logId);
1
  • Thank you,Its same as Rahul said and extra on adding an OR.
    – Mujahidh
    Feb 5, 2015 at 8:24
0

mujas,it is better process to Create new model for this table.then you can used Magento collection functions on this new module.Which will satisfy. You process is so sticky and very usefull for quick works.

Module Config.xml code look like:

<?xml version="1.0" ?>
<config>
    <modules>
        <Amit_Custommodule>
            <version>1.0.0</version>
        </Amit_Custommodule>
    </modules>
    <global>
        <models>
            <custommodule>
                <class>Amit_Custommodule_Model</class>
                <resourceModel>custommodule_resource</resourceModel>
            </custommodule>
            <custommodule_resource>
                <class>Amit_Custommodule_Model_Resource</class>
                <entities>
                    <custommodule>
                        <table>wired_points</table>
                    </custommodule>
                </entities>
            </custommodule_resource>
        </models>
    </global>
</config>

And: Model can access via Mage::getModel("custommodule/custommodule")->getCollection();

See more at My Blog

Also @Rahul Say,you can use multiple where() as where clause

1
  • Thank you,Have to study this method also.i used to read your blog
    – Mujahidh
    Feb 5, 2015 at 8:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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