Reputation: 44
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. 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 .
Upvotes: 0
Views: 692
Reputation: 50107
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,
Upvotes: 1