$_GET["gcb"]);This loads the correct patient. I have my guests table linked to the patients table under models. All is good. but now I need to put the patient's name in the Header (so we know what patient these guest belong to). The patient's name is under patients.p_first_name and patients.p_last_name.Any ideas?"> Display field from model in header - Forums

Forums

Display field from model in header

ediaccount 01 Feb, 2016
How can I display a field from a model in the front list table header? I am linking one listing to another: Click on the name of a transplant patient in one list and you are taken to another list of the guests allowed to visit the patient. The link from the patient listing to the guests listing is working fine. I am using the following Where condition:

return array("patients.id" => $_GET["gcb"]);

This loads the correct patient. I have my guests table linked to the patients table under models. All is good. but now I need to put the patient's name in the Header (so we know what patient these guest belong to). The patient's name is under patients.p_first_name and patients.p_last_name.

Any ideas?
GreyHead 02 Feb, 2016
1 Likes
Hi ediaccount,

As you have the patient ID presumably you can use that to look up the Patient record from the patients table. I'd probably do it using custom PHP in the Header box of the listing.

Note: I think you could possibly use the Pre display processing box - but I'm not sure how to get the results back from that into the header.

Bob
bmurphey 02 Feb, 2016
Answer
I used PHP in the Header Box and it worked. I'm not too familiar with PHP, but the lines below seemed to do it:
<?php
echo'<h3>Guests for '.print_r($this->view->vars['rows']['0']['patients']['p_first_name'], true).' '.print_r($this->view->vars['rows']['0']['patients']['p_last_name'], true).'</h3>';
?>

There's probably a more elegant method, but this worked.

Thanks!
GreyHead 02 Feb, 2016
Hi bmurphey,

If it's working that will do fine :-)

Bob
bmurphey 18 Feb, 2016
Figured out another way to do this, in case anyone is interested, using a db query in the Header Box. This listing is a listing of guests associated with a patient and is linked to from the patient listing. Thus, the 'gcb' passed from the patient listing to this one is the patient table id and can be used to look up the patient name directly. Here is the code I used in the Header box:

<?php
$db =& JFactory::getDBO();
$query = "
    SELECT id, p_first_name, p_last_name
        FROM avh_chronoengine_chronoforms_datatable_patients 
        WHERE `id` = ".$_GET['gcb'].";"; 
if ($debug) echo $query;
$db->setQuery( $query );
$result =& $db->loadObject();
$first = $result->p_first_name;
$last = $result->p_last_name;
echo'<h3>Guests for '.$first.' '.$last.'</h3>';
?>
This topic is locked and no more replies can be posted.