For the create attribute, run this script in the magento root directory (you can edit it according to your requirements)
<?php
require_once('app/Mage.php');
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
$installer = new Mage_Eav_Model_Entity_Setup('core_setup');
$installer->startSetup();
$installer->addAttribute('catalog_product', 'lid', array(
'label' => 'LId',
'type' => 'int',
'input' => 'text',
'backend' => '',
'frontend' => '',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => false,
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => true,
'visible_in_advanced_search' => false,
'unique' => false
));
$installer->endSetup();
?>
Now your attribute is created, as I created. Then set the value you want see.
.
$product = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToFilter('lid', 123);
foreach ($product as $products) {
echo '<pre>';
print_r($products);
}
Lid Exist
$product = Mage::getModel('catalog/product')
->getCollection();
foreach ($product as $products) {
if($products->getLid()){
echo $products->getName().'-->'.$products->getLid().'<br>';
}
}