dongmi5015 2016-03-23 03:39
浏览 57
已采纳

PHP问题(免费制作)

I am having a small problem making a file "Free", as in it does not count towards a member on of my site. The row in the database is called "free". I basically want this code to check the database to see if a file is free. If it is to give a slightly different result to something that ISNT free (basically saying the file is free instead of it isn't).

I have no idea where i am going wrong, but right now it's jumping past the else statement and only using the code after.

The SQL Structure is:

     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条回答 默认 最新

  • dsebywql016137 2016-03-23 04:06
    关注

    Seems like it might be an issues comparing strings. Try using double quotes in your if statement:

    if ($row['free'] == "yes")
    

    PHP is less strict with double quotes that could possibly help.

    If that doesn't work try using a column that stores a boolean (true,false) instead of a string as it is much easier to test a boolean than a string so it would be

    if ($row['free'] == true)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据