簡體   English   中英

Drupal 7 - 檢索特定列的所有行的最合適方法是什么?

[英]Drupal 7 - What is the most appropriate way to retrieve all the rows of a particular column?

我正在使用以下代碼嘗試檢索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進行了檢查。

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

解決了!

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

應該:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM