Page 1 of 1

Record title (how to display multiple fields?)

PostPosted: Sat Mar 07, 2009 6:53 pm
by kokoro
Steve, & All,

I know I said I would try to avoid asking elementary questions but since my skill level is low it seems I can't avoid it :oops:

I checked my PHP & MySQL reference books but had no luck.

Steve provided the following code to enable multiple fields to be displayed in the jump menu

class tables_mdl_user {
function getTitle(&$record){
return $record->display('username');
}

function titleColumn(){
return 'CONCAT(firstname," ",lastname)';
} }

and it works perfectly. I thought I'd be greedy and try to display the record name as 'firstname' , 'lastname' as follows:

class tables_mdl_user {
function getTitle(&$record){
return $record->display 'CONCAT(firstname," ",lastname)';
}

function titleColumn(){
return 'CONCAT(firstname," ",lastname)';
} }

But had no luck.

Also, (not directly related but) I noticed that in my production site, with 3367 records in a table, the jump menu does not appear at all...?

Jason

Record title (how to display multiple fields?)

PostPosted: Sat Mar 07, 2009 7:16 pm
by rdb
Try

class tables_mdl_user {
function getTitle(&$record){
return $record->display('firstname') . " " . $record->display('lastname)';
}

PostPosted: Sat Mar 07, 2009 9:31 pm
by kokoro
rdb,

Thanks! That did it. Just curious, as I am trying to learn as much as possible as I go, is the code you provided a convention of PHP? I mean the method you provided for displaying multiple records with a space in between them. I definitely need to study it (PHP) more because 'picking it up as I go' is pretty rough.

Jason

PostPosted: Sun Mar 08, 2009 8:49 am
by rdb
Hi Jason,

Let me preface my comments by saying that I'm a newbie with XF and still moderately green with PHP. I've written programs for many years, but mostly in C/C++. That helps, but there is still lots to learn about PHP. That's my disclaimer anyways.

Knowing PHP will help a lot. However I just tested the display() function and found that it needed to be given a field name; it didn't work being handed an expression. So, to get the job done that you want (multiple strings concatenated together), your function has to build that string itself using multiple calls to the display() function. The period (.) is a PHP string concatenation operator.

I would strongly recommend spending some time getting to know both PHP and MySQL. They are heavily used in the web site and web application development world. If you plan on continuing to do work in the web-based field, you'll run into these tools often and it will pay off in spades if you get to know them well.

Have fun!

Cheers.