PHP问题(免费制作)

时间:2016-03-23 03:39:54

标签: php mysql

我在制作文件“免费”时遇到一个小问题,因为它不计入我网站上的成员。数据库中的行称为“空闲”。我基本上希望这段代码检查数据库,看看文件是否是免费的。如果是给ISNT免费的东西稍微不同的结果(基本上说文件是免费的而不是它)。

我不知道我哪里出错了,但是现在它跳过了else语句并且只使用了之后的代码。

SQL结构是:

     CREATE TABLE IF NOT EXISTS `torrents` (
       `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
       `info_hash` varchar(20) CHARACTER SET latin1 COLLATE latin1_bin NOT       NULL DEFAULT '',
       `name` varchar(255) NOT NULL DEFAULT '',
       `filename` varchar(255) NOT NULL DEFAULT '',
       `save_as` varchar(255) NOT NULL DEFAULT '',
       `search_text` text NOT NULL,
       `descr` text NOT NULL,
       `ori_descr` text NOT NULL,
       `category` int(10) unsigned NOT NULL DEFAULT '0',
       `hits` int(10) unsigned NOT NULL DEFAULT '0',
       `times_completed` int(10) unsigned NOT NULL DEFAULT '0',
       `leechers` int(10) unsigned NOT NULL DEFAULT '0',
       `seeders` int(10) unsigned NOT NULL DEFAULT '0',
       `last_action` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
       `visible` enum('yes','no') NOT NULL DEFAULT 'yes',
       `banned` enum('yes','no') NOT NULL DEFAULT 'no',
       `owner` int(10) unsigned NOT NULL DEFAULT '0',
       `countstats` enum('yes','no') NOT NULL DEFAULT 'yes',
       `free` enum('yes','no') DEFAULT 'no',
       `req` tinyint(1) NOT NULL DEFAULT '0',
       `reseed` enum('yes','no') DEFAULT 'no',
       `last_reseed` int(11) NOT NULL DEFAULT '0',
       `picone` varchar(255) NOT NULL DEFAULT '',
       `pictwo` varchar(255) NOT NULL DEFAULT '',
       `picthree` varchar(255) NOT NULL DEFAULT '',
       `anonymous` enum('yes','no') NOT NULL DEFAULT 'no',
       PRIMARY KEY (`id`),
       UNIQUE KEY `info_hash` (`info_hash`),
       KEY `owner` (`owner`),
       KEY `visible` (`visible`),
       KEY `category_visible` (`category`,`visible`),
       KEY `leechers` (`leechers`,`seeders`),
       KEY `leechers_2` (`leechers`,`seeders`),
       KEY `completed_by` (`completed_by`),
       FULLTEXT KEY `ft_search` (`search_text`,`ori_descr`)
     ) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=144427 ;










    $downl = ($CURUSER["downloaded"] + $row["size"]);
      $sr = $CURUSER["uploaded"] / $downl;
    switch (true)
    {
case ($sr >= 4):
    $s = "w00t";
    break;
case ($sr >= 2):
    $s = "grin";
    break;
case ($sr >= 1):
    $s = "smile1";
    break;
case ($sr >= 0.5):
    $s = "noexpression";
    break;
case ($sr >= 0.25):
    $s = "sad";
    break;
    case ($sr > 0.00):
    $s = "cry";
    break;
default;
    $s = "w00t";
    break;
    }

      $sr = floor($sr * 1000) / 1000;
        $sr = "<font color='".get_ratio_color($sr)."'>".number_format($sr, 3).
    "</font>&nbsp;&nbsp;<img src=\"pic/smilies/{$s}.gif\" alt='' />";

    if ($row['free'] == 'yes')
        {
    ?>
    <tr><td align='right' class='heading'>Ratio After Download</td><td><del><?php echo $sr;?>       

    Your new ratio if you download this torrent.</del> <b><font size="" color="#FF0000">[FREE]</font></b>
     (only upload stats are recorded)</td></tr>
    <?php
    }
    else
    {
    ?>
    <tr><td align='right' class='heading'></td><td>
    <b><font color="#FFFF00">Your ratio if you download this torrent wil be: </font></b><?php echo $sr;?> <?=$uped?></td></tr>

1 个答案:

答案 0 :(得分:1)

似乎比较字符串可能是一个问题。尝试在if语句中使用双引号:

if ($row['free'] == true)

PHP不太严格,双引号可能会有所帮助。

如果这不起作用,请尝试使用存储布尔值(true,false)而不是字符串的列,因为测试布尔值比使用字符串更容易,因此它将是

{{1}}