Q:

How to fetch row from custom table in drupal 7? 

I have used
 $member_id = 12;

 $results = db_query("select * from {customorders} where id = :fid", array(':fid' => $member_id));
 foreach($results as $result) {
       $name = $result['name'];
 }

but I get error Fatal error: Cannot use object of type stdClass as array
so what could be solution , and please correct me if I have written wrong query for select
i want "select * from customorders where id = 12"
and customorders is my created custom table in Drupal database
Please help me..
Thanks

A:

The $result variable is returned as an array of objects.  So you should use $result->name instead of $result['name']. 
Your code can be fixed to be like that:
 $member_id = 12;

 $results = db_query("select * from {customorders} where id = :fid", array(':fid' => $member_id));
 foreach($results as $result) {
       $name = $result->name; // THE EDITED LINE. 
 }

Hope this works... Muhammad.