douluo1330 2015-08-06 17:20
浏览 78
已采纳

php半冒号分隔,有条件的问题

Hi: This is my first question... So please be easy on me. :)

I've got most of my problem resolved but can't figure out one little thing... Here is my database structure...

RAK 0 ; none ; WCU ; gray ; 20C ; 40C ; grey ; grey ;
RAK 1 ; none ; WCU ; gray ; 20C ; 40C ; grey ; grey ;
RAK 2 ; none ; WCU ; gray ; 20C ; 40C ; red ; red ;
RAK 3 ; none ; ACU; gray ; 20C ; 40C ; red ; red ;

Here is my variable structure....

<?php

$rack = array();
if (($handle = fopen("status.txt", "r")) !== FALSE)
{
    while (($data = fgetcsv($handle, 1000, ";")) !== FALSE)
{
    if(substr(trim($data[0]), 0, 3) == 'RAK')
    {
        $board = trim($data[0]);
        $temp = $data[2];
        $rack[ $board ] = $temp;
    }
   }
   fclose($handle);
    }
   ?>

What I have are several divs next to each other and they are set to dislay or not. Display is important because when it displays none the divs move next to each other instead of maintaining the gap as when you hide a div.

<div class="rack3wcu" style="display: <?php echo $rack['RAK 3']; ?>;">

It actually has served me really well but now I got a curve ball with the acu, wcu. This file is spit out from a super computer and normally the python guys will output the direct word i need to echo... but in this case i need to do something different depending on the two choices.

so what I need is if it is ACU then echo none, else it is WCU then send a different echo saying yes, or none actually depending on the toggle...

Listen folks, I'm horrible with conditionals. Can someone help a brother out?

  • 写回答

2条回答 默认 最新

  • duanhuan1147 2015-08-06 17:33
    关注

    If "ACU" and "WCU" are not the only possible values:

    <div class="rack3wcu" style="display: <?php echo ( trim($rack['RAK 3']) == 'ACU') ? 'none' : ( ( trim($rack['RAK 3']) == 'WCU') ? 'block' : ''); ?>;"></div>
                           // Note that in this situation, you have to decide what to echo when the value is not ACU and not WCU ^^^^ 
    

    If "ACU" and "WCU" are the only possible values, this will be enough:

    <div class="rack3wcu" style="display: <?php echo ( trim($rack['RAK 3']) == 'ACU') ? 'none' : 'block'; ?>;"></div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!