By ceci123 on
I am trying to create a summary section/table "Printable Section for Interacting Medications" with the information stored on the "$variables['medication_name']" array.
I thought I could just do this "print $int_medication_name;" on the search-result.tpl.php page but it keeps looping and placing it after each result. I just don't understand how this works.
As shown below I have added a function phptemplate_preprocess_search_result () to the template.tpl.php file which gets displayed like this "print $medication_name;" on the search-result.tpl.php page.
template.tpl.php CODE
<?php
/** Grab field_designation and field_medication_name and place it into an array.*/
function phptemplate_preprocess_search_result (&$variables) {
$result = $variables['result'];
$variables['designation'] = $result['node']->field_designation[0]['value'];
$variables['medication_name'] = $result['node']->field_medication_name[0]['value'];
}
?>
search-result.tpl.php CODE
<?php
// $Id: search-result.tpl.php,v 1.1.2.1 2008/08/28 08:21:44 dries Exp $
/**
* @file search-result.tpl.php
* Default theme implementation for displaying a single search result.
*
* This template renders a single search result and is collected into
* search-results.tpl.php. This and the parent template are
* dependent to one another sharing the markup for definition lists.
*
* Available variables:
* - $url: URL of the result.
* - $title: Title of the result.
* - $snippet: A small preview of the result. Does not apply to user searches.
* - $info: String of all the meta information ready for print. Does not apply
* to user searches.
* - $info_split: Contains same data as $info, split into a keyed array.
* - $type: The type of search, e.g., "node" or "user".
*
* Default keys within $info_split:
* - $info_split['type']: Node type.
* - $info_split['user']: Author of the node linked to users profile. Depends
* on permission.
* - $info_split['date']: Last update of the node. Short formatted.
* - $info_split['comment']: Number of comments output as "% comments", %
* being the count. Depends on comment.module.
* - $info_split['upload']: Number of attachments output as "% attachments", %
* being the count. Depends on upload.module.
*
* Since $info_split is keyed, a direct print of the item is possible.
* This array does not apply to user searches so it is recommended to check
* for their existance before printing. The default keys of 'type', 'user' and
* 'date' always exist for node searches. Modules may provide other data.
*
* <?php if (isset($info_split['comment'])) : ?>
* <span class="info-comment">
* <?php print $info_split['comment']; ?>
* </span>
* <?php endif; ?>
*
* To check for all available data within $info_split, use the code below.
*
* <?php print '<pre>'. check_plain(print_r($info_split, 1)) .'</pre>'; ?>
*
* @see template_preprocess_search_result()
*/
?>
<dd>
<table border='0'>
<tr>
<td> <?php print strtoupper($medication_name); ?></td>
<td> <?php print strtoupper($int_medication_name); ?></td>
<td><?php print strtoupper($designation); ?></td>
</tr>
</table>
<table>
<tr><th>Print Summary for Drug Interactions<strong> (this is not working for me right now)</strong></th></tr>
<tr>
<td><?php print $int_medication_name; ?></td>
</tr>
</table>
</dd>
Can anyone help?
Thank you in advance.
C
Comments
Your template file is
Your template file is search-result.tpl.php. It acts on every single search result. In order to print the summary at the bottom you will have to modify search-results.tpl.php (notice the plural of results).
-= Gerrit Brands
I learned something new
I learned something new today. Thanks.
So I took your advise and added this function (below) to template.tpl.php:
After that I tried to echo the results on the search-results.tpl.php file:
print $print_summary;I don't see any results. What am I doing wrong? Can you give me an example of how to achieve this?
Thank you for your help.
Ceci
Try setting your $result
Try setting your $result variable to the following:
Note that results is plural.
See template_preprocess_search_results() for more info.
-= Gerrit Brands
$result array results data but am unable to print them.
As suggested I set the $result variable and when printing the array with print_r() returns the following.
The values are there but my problem is not being able to grab them using this function:
Somehow the variable $print_summary is always empty when I tried printing on the search-results.tpl.php file.
I have a deadline coming soon and I must get this part working. Thank you for your help.
Thank you.
~Cec
Can you post the results of
Can you post the results of setting
$variables['print_summary'] = '<pre>' . print_r($result,1) . '</pre>';. If that doesn't show anything how about setting it to the following:$variables['print_summary'] = 'HELLO!';If you don't get anything outputted from either of the two examples above are you sure you're clearing the template cache?
-= Gerrit Brands
If I'm understanding the
If I'm understanding the issue correctly, you need to process the result set as an array. Arrays cannot be assigned to/treated as scalar values.
This is done by iterating through the result set using the foreach php construct.
got it working!
I think I got it working...yeah!
I just did this:
Thanks for your help! I really appreciate it.
Cec