javascript - php semi colon delimited, have problems with a conditional

915

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 >

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?

999

Answer

Solution:

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

<div ></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 ></div>
213

Answer

Solution:

I guess you would want something like this:

<?php
foreach ($rack as $rackIdentifier => $rackType) {
    switch ($rackType) {
        case 'WCU':
?>
            <!-- display some html for WCU-->
<?php
            break;
        case 'ACU':
?>
            <!-- display some html for ACU -->
<?php
            break;
        default:
?>
            <!-- display some html for unknown type (not WCU, not ACU) -->
<?php
    }
}
?>

People are also looking for solutions to the problem: PHP getting work day range of a week

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.