Quantcast
Channel: Magento Expert » php
Viewing all articles
Browse latest Browse all 36

How to check an already existing record in Magento?

$
0
0

Hi,

I am trying to perform an SQL query kind of thing where I need to check if my database table contains a particular record or not. If it does, do nothing else add the record which isn\\\’t present.

My table sample contains fields like sample_id (auto-incremented), order_id, order_email_id, review_request, coupon_sent

It has got 4 records having order_ids (71, 74, 126, 165)

My $id contains (71, 74, 126, 165, 166, 167)

So ideally the below query should check against existing records (71, 74, 126, 165) and insert new ones (166, 167). I echoed the query and it returned right but it still incudes the other two records as already existing as well which it should not.

Is there any other way to check the value of an existing field in the table in Magento?

$sample = Mage::getModel(\’sample/sample\’)->getCollection()->addFieldToFilter(\’order_id\’, $id)->addFieldToSelect(\’order_id\’);

if($sample != \” \”)

{echo \”Record Already present!\”;}

else {echo \”Record needs inserting!\” ;}

Any help is appreciated. Thanks in advance

 

The post How to check an already existing record in Magento? appeared first on Magento Expert.


Viewing all articles
Browse latest Browse all 36

Trending Articles