我有一个包含字段 A、B、C、D、E 的数据库表(furcodes),我使用此代码在 Joomla 站点中创建兑换代码系统:
<?php
$redeem_code = JRequest::getString('redeem_code', '', 'post');
$db =& JFactory::getDBO();
$query = "
SELECT COUNT(`B`)
FROM `furcodes`
WHERE `B` = '$redeem_code' ;
";
$db->setQuery($query);
$count = $db->loadResult();
if ( $count ) {
$mainframe =& JFactory::getApplication();
$mainframe->enqueuemessage('You have succesfully redeemed this fur code');
return false;
} else {
$mainframe =& JFactory::getApplication();
$mainframe->enqueueMessage(JText::_('Invalid code. Please check and try again.'), 'error');
return false;
}
?>
我使用计数来检查数据库中是否存在此代码,但我还需要从“E”列中获取字段,该字段说明此代码之前是否已使用(值 0=未使用或 1=已使用,一次使用对于每个代码)并创建一个这样的 if:
if $used == 1
echo "This code has been used"
有什么帮助吗?
我使用的最终代码,它可能对其他人有帮助。
<?php
$your_fur_code = JRequest::getString('fur_code', '', 'post');
$db =& JFactory::getDBO();
$query = "SELECT `E` FROM `furcodes` WHERE `B` = '$your_fur_code'";
$db->setQuery($query);
$code_used = $db->loadResult();
if ( $code_used == "1" ) {
$mainframe =& JFactory::getApplication();
$mainframe->enqueueMessage(JText::_('The code has already been used.'), 'error');
return false;
} if ( $code_used == "0" ) {
$mainframe =& JFactory::getApplication();
$mainframe->enqueuemessage('You have succesfully redeemed this code');
return false;
} else {
$mainframe =& JFactory::getApplication();
$mainframe->enqueueMessage(JText::_('Invalid code. Please check and try again.'), 'error');
return false;
}
?>