Multiple labels with editor
Multiple labels with editor
mRender
Posts: 151Questions: 26Answers: 13
Here is what I currently have:
if ( !isset($_POST['action']) ) {
$data['projectList'] = $db->query( 'select' )
->distinct( true )
->table( 'projects' )
->get( 'userprojects.projectid as value' )
->get( 'projects.projectname as label' )
->join( 'userprojects', 'userprojects.projectid = projects.projectid' )
->join( 'clients', 'clients.clientid = projects.clientid' )
->where( 'userprojects.userid', $userid )
->exec()
->fetchAll();
This works fine. This is what I really want though:
if ( !isset($_POST['action']) ) {
$data['projectList'] = $db->query( 'select' )
->distinct( true )
->table( 'projects' )
->get( 'userprojects.projectid as value' )
->get( 'projects.projectname - clients.clientname as label' ) <<<<<<<<<<<<<<<<<<<<<<<<
->join( 'userprojects', 'userprojects.projectid = projects.projectid' )
->join( 'clients', 'clients.clientid = projects.clientid' )
->where( 'userprojects.userid', $userid )
->exec()
->fetchAll();
So basically two labels but only display them as one. I tried to do something like this:
$data['projectList'] = array();
while ( $row = $data->fetch() ) {
$data['projectList'][] = array(
"value" => $row['userprojects.projectid'],
"label" => $row['projects.projectname'].' '.$row['clients.clientname']
);
}
But I couldn't get it to work correctly. Any help would be greatly appreciated.
This question has accepted answers - jump to:
This discussion has been closed.
Answers
Your solution of going it in PHP is the way to do it when using the Editor DB library's fluent API as it doesn't current support functions (i.e. you can use
concat
unfortunately).What you tried to use doesn't work since
$row['userprojects.projectid']
doesn't exist. You aliased it to$row['value']
.You would also need to add individual gets for
projects.projectname
andclients.clientname
.Allan
So this code here
Gives me this error: Call to a member function fetch() on a non-object in /var/www/vhosts/time.mmitco.com/httpdocs/ss_timecard.php on line 74
Line 74 is: while ( $row = $data->fetch() ) {
You've already run
fetchAll();
on the result. That give you an array. You probably want to read the result in a result variable ($res
) and drop thefetchAll()
call.Allan
Wow, this works :) Thank you Allan! You da man!
Is there a ->order or ->sort type of function to make the labels alphabetical in the list?
order() :-)
Allan