2012-05-13 15 views
0

我使用下面的代碼,試圖找回在Drupal 7特定列的所有行:Drupal 7 - 檢索特定列的所有行的最合適方法是什麼?

// Use Database API to retrieve current posts. 
    $query = db_select('field_data_field_phone_number', 'n'); 
    $query->fields('n', array('field_phone_number_value')); 

    // Place queried data into an array 
    $phone_numbers = $query->execute()->fetchAssoc(); 

我認爲這是足以檢索整個列,但是當我使用以下行顯示查詢,沒有值顯示:

drupal_set_message('<pre>'.print_r($phone_numbers, true).'</pre>'); 

我知道一個事實,即有在表中的相關值我一直在使用MySQLWorkbench檢查。

任何幫助將不勝感激,謝謝!

回答

2

解決!

$phone_numbers = $query->execute()->fetchAssoc(); 

應該是:

$phone_numbers = $query->execute()->fetchCol(); 
相關問題