dB field to unordered list
I'm writing a module that pulls some field values from a MySQL table. I need to include a price field in an unordered list, but am having trouble.
I can read the table and load prices into $fee1 and $fee2.
In the body of my node I have a list that looks something like this (The input format is set to 'PHP code'):
<ul>
<li style="list-style-type: none; font-weight:bold">Membership Fees</li>
<li><?php printf("$%.0d\n", $fee1); ?> for the first member</li>
<li><?php printf("$%.0d\n", $fee2); ?> for each additional member</li>
</ul>The resulting output looks like this:
Membership Fees
* $0 for first member
* $0 for each additional member
I know the printf() function is working, because if I change a list item to
<li><?php printf("$%.0d\n", 24.56); ?> for the first member</li>The resulting output looks like this:
Membership Fees
* $25 for first member
* $0 for each additional member
Note, rounding to $25 here is as expected.
I've also validated $fee1 and $fee2 via print_r().
So, the problem lies in how to get the $fee1 and $fee2 variables to be a part of a list item. The solution is probably straight forward, but it eludes me. Your help is appreciated.

So this prints out the
So this prints out the correct values?
<?phpecho $fee1.'<br>'.$fee2;
?>
did you try
<?php echo printf("%.0f",$fee1); ?>Thanks MissyM for your
Thanks MissyM for your response.
I don't think the problem lies in the printf() formatting, but rather that the values for $fee1 and $fee2 are not available in the "Description" section of my node. In testing, I've set their value within the "Description" as "$fee1 = 123.45" and "$fee2 = 234.56". With this done, the printf() display is just fine.
The MySQL query occurs in mymodule_form_alter($form_id, &$form). I've even declared $fee1 and $fee2 as global within that function. So, how do I coax my node to 'see' these values?
Thanks again for your help.
I haven't used
I haven't used hook_form_alter but I did use the hook_nodeapi and I struggled with this type of issue until I got Devel. Devel helped me figure out what variables I had and how to access them. I'm not sure what you are trying to do (overall), but I used hook_nodeapi to add some calculated values and lists of query results to my forms and, once I figured things out, it worked great.
Here is how to do that:
// in this module
function xxxmodule_nodeapi(& $node, $op, $a3 = NULL, $a4 = NULL) {
switch ($op) {
case 'view' :
// when the users are viewing this type of node -> get propertyX using the show_propertyX function and put it into the value field
if ($node->type == 'whatever') {
$node->content['propertyX'] = array(
'#value' => show_propertyX($node->nid),
'#weight' => 1
);
... etc.
It really is simple but it took a while to figure it out.
Missy.
Missy, I didn't quite follow
Missy,
I didn't quite follow your example, so I took another route:
I set variables using 'variable_set()' in 'mymodule_form_alter()' and then retrieved them in the 'Description' section of my node using 'variable_get()'. It worked just fine and the formatting is OK.
Does this approach make sense? Am I possibly creating any problems by using the Drupal variable table?
Thanks again for your suggestions.