1

Hello all i am new but got so many helps from here. Thanks to all the people who helped. Now i am facing a problem in magento e-commerce for making a loop query of top 10 point holders. Well i have made a separate database which contain the points .

my database is table : magentodatabase_points Now here is total 3 colums - 1. ID 2. User_id 3. points

well now, here i would like to make a loop of top 10 members contain the highest points i have tried but failed so can anybody help me on that.

$resource = Mage::getSingleton('core/resource');

$readConnection = $resource->getConnection('core_read');

$table = $resource->getTableName('database_points');
$query = 'SELECT user_id FROM ' . $table . ' ORDER BY points DESC LIMIT 10';
$results = $readConnection->fetchAll($query);

well but after that i have tried with php for loop but that is not supporting for magento. So can anybody know what will be the loop code for magento.

Well, one more help would be greatful for me how do i get magento customer names from the using the top results of user_id because i will get only the results not the names.

Anyways that is not that important because i hope i will solve it by my own.

So, please if anyone can help me on the loop query of top 10 point holders.

Thanks in advace and sorry for my bad english

1
  • Your code looks like it should work. fetchAll() returns an array, so that has nothing to do with Magento, but rather with PHP. How is it not supported? Are you getting an exception? if so, what is it? Commented Feb 18, 2012 at 15:57

2 Answers 2

3

If your table name and fields exist then you can just add this below your code:

foreach ($results as $result) {
        $user_id = $result['user_id'];
        echo $user_id; // or do whatever you wanted to with the variable
}

You should consider using Magento's Models to do this instead. There's an excellent tutorial series from Alan Storm on MagentoCommerce's website: http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-5-magento-models-and-orm-basics

For the customer's names you can try this in your loop:

foreach ($results as $result) {
        $user_id = $result['user_id'];

        $customer = Mage::getModel('customer/customer')->load($user_id);
        print_r($customer);
}
Sign up to request clarification or add additional context in comments.

Comments

0

May be because your field name has uppercase for u of user_id correctd "User_id" and you are using lowercase in your query. else your method is fine to work with magento

for gettting customer, if User_id u get from this result is a customer id then $customer_data = Mage::getModel('customer/customer')->load(User_Id); would give u all detail of customer. you can fetch name from this using $customer_data->getName() method

1 Comment

well i have sold my problem thanks a lot for the help . i got the user name now i am trying for adding photo upload to users

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.