简体   繁体   English

如何从数据库的一个表中获取显示的数据-Drupal

[英]How to get data displayed from one table from database -Drupal

I am creating a table view for my custom module that displays user some custom data that he created. 我正在为我的自定义模块创建一个表视图,该视图向用户显示他创建的一些自定义数据。

Example table hour: 表格小时示例:

hour_id    hour
  1       07:00
  2       07:30
  3       08:00
  4       08:30

Example table data: 表格数据示例:

user_id    user   hour_start    hour_end
  1        name     1              3
  2        name     1              2

Note: I save ID from table hour to table data. 注意:我将表格时间中的ID保存到表格数据中。 User has a dropdown menu for start and end. 用户具有一个用于开始和结束的下拉菜单。

$result = db_query("SELECT ho.hour,h.hour FROM {data} t
                    INNER JOIN {hour} ho ON t.hour_start=ho.hour_id
                    INNER JOIN {hour} h ON t.hour_end=h.hour_id
                    WHERE t.made=:t",array(":t"=>$temp_user));


    $rows = array();
    foreach($result as $row){
    $rows[] = array ('data' => 
    array(
        $row -> hour, // putting ho.hour gives error
        $row -> hour, // putting h.hour gives error
        ),
    );

My problem is that i get in the table only one hour. 我的问题是我只能在桌子上坐一个小时。 How can i get for row one 07:00(1) for one column and 08:00(3) without creating a separate tables for hour_start and hour_end . 如何在不为hour_start和hour_end创建单独表的情况下为第一列的07:00(1)和08:00(3)获得第一行。

Try using column aliases. 尝试使用列别名。 Change the query to: 将查询更改为:

SELECT ho.hour ho_hour, h.hour h_hour FROM {data} t ...

and then get the data using: 然后使用以下方法获取数据:

$row -> ho_hour,
$row -> h_hour,

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将数据从一个数据库表传输到另一个数据库中的表 - How to transfer data from one table of a database to a table in another database 如何从一个数据库到另一个数据库获取数据? - How to get a data's from one database to other database? 如何在不同数据库表的一个页面中显示数据 - how to display data in one page from different database table 如何将两个表中的数据导入另一个数据库中的一个表 - how to import data from two tables into one table in another database 将数据从一个数据库表获取到另一个数据库表 - Getting data from one database table into another database table 从视图从一个数据库到另一个数据库中的表的数据传输 - Data transfer from a view from one database to a table in another database 如何从 PHP 上的 $_GET 值将数据插入数据库表 - How to insert data to database table from $_GET value on PHP 如何通过延迟加载和单表继承从数据库获取数据 - How to get data from database with lazy loading and single table inheritance 如何将一个oracle数据库表中选中的数据列实时插入到另一个oracle数据库表中 - How to insert the selected data columns from one oracle database table into another oracle database table in real time 你如何 select 来自另一个表的数据与 mySQL 查询数据库中一个表的匹配条件? 稍后比较并获取我们需要的数据 - How do you select a data from another table with matching criteria from one table in mySQL query database? Later to compare and get data that we need
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM