简体   繁体   English

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

[英]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.

相关问题 Codeigniter 检索列中出现次数最多的前 5 行 - Codeigniter retrieve top 5 most occurring rows in column 调用递归函数的最合适方法是什么? - What's the most appropriate way to re-call a recursive function? Drupal 7-通过代码创建多个自定义菜单项的最合适方法 - Drupal 7 - Most Appropriate Way to Create Multiple Custom Menu Items Via Code 有没有办法检索具有特定密码的所有用户 - Is there a way to retrieve all users that have a particular password 有没有一种方法可以在所有行上执行,而不仅仅是最近的? - Is there a way of executing on all rows not just the most recent? 在Drupal 7中创建或删除许多节点的最有效方法是什么 - What is the most performant way to create or delete many nodes in Drupal 7 从这个特定文件中获取数据的最有效方法是什么? - What's the most efficient way to grab data from this particular file? 更新或检索数据库中的行的最佳方法是什么? - What is the best way to update or retrieve rows in database? 检索MySQL表注释的最优雅方法是什么? - What's the most elegant way to retrieve a MySQL table comment? 在具有 PHP 和 nodeJS 依赖项的项目之间集成覆盖率的最合适方法是什么? - What is the most appropriate way to integrate coverage between a project with PHP and nodeJS dependencies?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM