[英]Drupal 7 - What is the most appropriate way to retrieve all the rows of a particular column?
I am using the following code in an attempt to retrieve all the rows of a particular column in 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();
I thought this was enough to retrieve an entire column, but when I use the following line to display the query, there are no values to display: 我认为这足以检索整个列,但是当我使用以下行显示查询时,没有要显示的值:
drupal_set_message( '<pre>'.print_r($phone_numbers, true).'</pre>');
I know for a fact that there are relevant values in the table as I have checked using MySQLWorkbench. 我知道有一个事实,表中有相关的值,因为我已经使用MySQLWorkbench进行了检查。
Any help would be greatly appreciated, thanks! 任何帮助将不胜感激,谢谢!
Solved! 解决了!
$phone_numbers = $query->execute()->fetchAssoc();
Should be: 应该:
$phone_numbers = $query->execute()->fetchCol();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.