$customers = Mage::getResourceModel('customer/customer_collection') 
                  ->addAttributeToSelect('*') 
                  ->addAttributeToFilter('firstname', $firstName);

The above code will only load the collection.

To get customer details by firstname, we need to loop through customer collection object and then get customer id. Finally just load the individual customer object as below

$model = Mage::getModel('customer/customer');

$customerCollection = $model->getCollection()
  ->addAttributeToSelect('*')
  ->addAttributeToFilter('firstname', array('like' => $variableFirstName));

foreach($customerCollection as $customerObject) 
{       
$customer = $model->load($customerObject->getId());
echo '<b>'.$customer->getFirstname() . $customer->getLastname().'</b><br/>';
}

In case, if we want to filter by lastname,  just change to

->addAttributeToFilter('lastname', array('like' => $variableLastName))

 

Categorized in: