GROUP_CONCAT & Left Join loading only 1 row - Joomla! Forum - community, help and support


create table `jos_workorder` (
`w_id` int(25) not null auto_increment,
`wo_num` varchar(10) not null,
`wo_name` varchar(255) not null,
`wo_desc` text not null,
`wo_catid` int(25) not null,
`wo_officeid` int(25) not null,
`wo_assignedby` int(25) not null,
`wo_dateposted` timestamp not null default current_timestamp on update current_timestamp,
`wo_contactid` int(25) not null,
`wo_duedate` date not null,
`wo_completedate` timestamp not null default '0000-00-00 00:00:00',
`wo_status` enum('complete','review','in-progress') default 'in-progress',
primary key (`w_id`)
) engine=myisam default charset=utf8 auto_increment=5 ;

create table `jos_workorder_tasks` (
`id` int(25) not null auto_increment,
`w_id` varchar(25) not null,
`userid` int(25) not null,
`task` varchar(255) not null,
`file` varchar(255) not null,
`added` timestamp not null default current_timestamp on update current_timestamp,
primary key (`id`)
) engine=myisam default charset=utf8 auto_increment=4 ;

code: select all

$db = jfactory::getdbo();
$query = 'select #__workorder.*, #__workorder.*, '.
             'group_concat(#__workorder_tasks.task) tasks '.
             'from #__workorder '.
             'left join #__workorder_tasks '.
             'on (#__workorder.w_id=#__workorder_tasks.w_id)';
      
$db->setquery($query);
$results = $db->loadobjectlist();
return $results;


array ( [0] => stdclass object ( [w_id] => 1 [wo_num] => 12-0001 [wo_name] => test project [wo_desc] => [wo_catid] => 2 [wo_officeid] => 1 [wo_assignedby] => 43 [wo_dateposted] => 2012-12-23 13:58:24 [wo_contactid] => 1 [wo_duedate] => 2012-12-31 [wo_completedate] => 0000-00-00 00:00:00 [wo_status] => in-progress [tasks] => test task 1,task #2 workorder #1,task #3 workorder #1 ) )

i have @ least 4 entries in workorders. doing wrong?
thanks.

a couple of points, may relevant:

the select has same table twice did not mean.

group_concat used group clause.





Comments

Popular posts from this blog

How to change text Component easybook reloaded *newbee* - Joomla! Forum - community, help and support

After Effect warning: A problem occurred when processing OpenGL commands

Preconditions Failed. - Joomla! Forum - community, help and support