doupike2351 2013-07-25 19:35
浏览 15

php变量忽略布尔值? 即使不允许按钮,按钮也会继续上桌

$button = $button == TRUE ? "<span class='button_join'>Join</span>" : "";

Basically, if button = TRUE, then show up the button. But the buttons is always showing when I have $button == TRUE ? on, but I never see it getting true anywhere?

Mysql results showing for 2 rows "In Progress", and for 1 row "Available".

But the problem is, that the button shows for every row, Ill post a picture so you will know what I am talking about:

img http://gyazo.com/4ed23f9793c6f69812d6140f64cea2a2.png

What's wrong?

This is the code:

            while ($row = $query->fetch(PDO::FETCH_ASSOC))
            {
                if (!Ping::remote($row['server_ip'], $row['server_port']))
                {
                    $status = "Offline";
                }
                else
                {
                    $status = $row['server_status'];
                }

                if ($status != "In Progress" || $status != "Offline" || $status != "Full" || $status == "Available")
                {
                    $joinButton = TRUE;
                }
                else
                {
                    $joinButton = FALSE;
                }

                Template::drawTableRow (
                    $row['server_name'], 
                    $row['server_players'], 
                    $row['server_map'], 
                    $row['server_status'],
                    $joinButton
                );

            }

drawTableRow:

    public static function drawTableRow($name, $players, $map, $status, $button)
    {

        $button = $button == TRUE ? "<span class='button_join'>Join</span>" : "";

        $status = $status == "Full" || $status == "In Progress" || $status == "Offline" ? "<span class='status_error'>".$status."</span>" : "<span class='status_success'>".$status."</span>";

        echo
        '
            <tr>
                <td>
                    '.$name.'
                </td>
                <td>
                    '.$players.'
                </td>
                <td>
                    '.$map.'
                </td>
                <td>
                    '.$status.'
                </td>
                <td>
                    '.$button.'
                </td>                   
            </tr>
        ';
    }

What's wrong there?

  • 写回答

4条回答 默认 最新

  • dou4381 2013-07-25 19:36
    关注

    You need parenthesis:

    $button = ($button == TRUE) ? "<span class='button_join'>Join</span>" : "";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Fluent udf 编写问题
  • ¥15 求合并两个字节流VB6代码
  • ¥15 Pyqt 如何正确的关掉Qthread,并且释放其中的锁?
  • ¥30 网站服务器通过node.js部署了一个项目!前端访问失败
  • ¥15 WPS访问权限不足怎么解决
  • ¥15 java幂等控制问题
  • ¥15 海湾GST-DJ-N500
  • ¥15 氧化掩蔽层与注入条件关系
  • ¥15 Django DRF 如何反序列化得到Python对象类型数据
  • ¥15 多数据源与Hystrix的冲突