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