2015-07-21 115 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>'); ?> 
相關問題