0

i've problem using db_select it return strange object instead of the result here is the code

function _table_subscrib(){
  $result = db_select('user_company','uc')
->fields('uc',array('user_company_uid','user_company_nid','user_company_sub_number','user_co    mpany_date'))
          ->extend('TableSort')
         ->extend('PagerDefault') 
         ->limit(50)
         ->execute();   

$header = array('User Name','Company Name','Subscribtion Number','Date');

$rows = array();
while($data = $result->fetchAssoc());
{
    $rows[] = array(
        $data['user_company_uid'],
        $data['user_company_nid'],
        $data['user_company_sub_number'],
        $data['user_company_date']
    );
    drupal_set_message("ssdsd");
}

$output = theme_table(
            array(
                "header" => $header,
                "rows" => $rows,
                "attributes" => array(),
                "sticky" => true, 
                "caption" => "",
                "colgroups" => array(),
                "empty" => t("Table has no row!") // The message to be displayed if table is empty
                )
            ).theme("pager");

return $output;

}

here is the object returned too

DatabaseStatementBase Object ( [dbh] => DatabaseConnection_mysql Object ( [shutdownRegistered:protected] => [target:protected] => default [key:protected] => default [logger:protected] => [transactionLayers:protected] => Array ( ) [driverClasses:protected] => Array ( [SelectQuery] drupal......

thanks

0

You set incorrect semicolon at the end, remove it: while($data = $result->fetchAssoc());

And next manner looks more clear, instead using while:

foreach($result as $data) {
    $rows[] = array(
        $data->user_company_uid,
        $data->user_company_nid,
        $data->user_company_sub_number,
        $data->user_company_date,
    );
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.