2015-07-21 64 views
1

我在数据库中有一个表,名为自定义字段类型。如果这匹配“textfield”,我想回显一个文本框,如果它匹配“textarea”,我想回显一个文本区域。PHP - 如何检查变量是否匹配数据库条目?

有人能让我知道我在下面做错了什么吗?

<?php if($this->item->custom_field_type1 == 'textfield') { 
     echo 'this is a text field'; 
    } 
    ?> 
+0

检查,如果($这个 - >用品 - > custom_field_type1 == '文本') –

回答

0

该解决方案可以帮助你

<?php if($this->item->custom_field_type1 == 'textfield') { 
     echo '<input type="text">'; 
    } 
if($this->item->custom_field_type1 == 'textarea') { 
     echo '<textarea></textarea>'; 
    } 
    ?> 
+0

感谢。我尝试了类似的东西,然后使用上面的确切代码,但它似乎仍然不起作用。我知道它可以看到数据库,因为所有其他字段都在工作。 – Rob88991

+0

'$ this-> item-> custom_field_type1'返回什么 –

+0

对不起,我想我在其他地方发现了问题,这与我尝试构建的joomla组件文件有关。感谢您的帮助,我在其他地方测试了它,并且代码非常棒。 – Rob88991

0
<?php echo ($this->item->custom_field_type1 == 'textfield'?'<input type="text" />':'<textarea></textarea>'); ?> 
相关问题