By calebm12 on
Am unsure what I am doing wrong here. I am trying to do a php if statement that if the field equals zero it will print. I have tried the following multiple different ways and nothing seems to be working. Def appreciate some guidance/direction on what i am doing wrong. I define the uc_sell_price in my template file preprocess.
<?php if ($uc_sell_price = '0.00000'): ?>
<div class="servicecontact">
<a href = "http://localhost/techsupport/contact">Contact for Price</a>
</div>
<?php else: ?>
<?php endif; ?>
many thanks!
Comments
Have you tried 0.0 (vs
Have you tried 0.0 (vs '0.00000')?
yes, just tried it. if i
yes, just tried it. if i leave the apostrophe it shows up regardless. if i remove apostrophe it doesnt show up regardless.
Missed you had a single '=',
Missed you had a single '=', try
$uc_sell_price == 0.0Still not working. I just
Still not working.
I just tried
I went and looked at the phpmyadmin and the sell_price field is 0.00000 for one record and 45.00000 for another. For both of these records they both end up printing the link.
Is the field type a string?
Is the field type a string? If yes, you will need '0.00000'
Still no go. I am wondering
Still no go. I am wondering if ubercart is playing a role in this not working. In my template.php file i am declaring the following:
If i just print the uc_sell_price, for one record it is printing $45.00 and for the other record its not printing anything. However if i go to phpadmin and look at the uc_products table the values related to these records are 45.00000 and 0.00000 for sell_price. this is a different table then the content_type_product.
Really perplexed as to what i can do from here.
I am confused on what you are
I am confused on what you are doing, $node ($vars['node']) is is already available in hook_preprocess_node() so why are you calling node_load() and node_build_content()?
As for the problem, you just want $node->content['sell_price'] (which is available in node.tpl.php), rendering it adds html so none of the tests I suggested would work.
Appreciate your patience on
Appreciate your patience on this. I apologize for my very very weak php background.....learning as i go.
In regards to the first question. I took that code directly from an ubercart theme (fusion core i believe).
I have tried printing directly the sell price
Once again it looks like it renders. As i get the following for one record "Price: $45.00" and nothing prints on the second record (the zero one).
If i do a print r to see all the fields i do see the sell_price and its not in the database table rendered.
This should help
A quick test shows that
if ( $node->sell_price == 0.00 )should workIf the type of $uc_sell_price
If the type of $uc_sell_price is string try this:
if ($uc_sell_price === '0.00000'):If the type of $uc_sell_price is int or float try this:
if ($uc_sell_price === 0):or
if ($uc_sell_price === 0.0):More detail: PHP Comparison Operators
This<?php if
This
<?php if ($node->sell_price == 0.00 ): ?>did it!
Thanks for hanging with me!!!