1

Can anyone please help me? I have a data in a column called column_hide the data is 0,1

I want to explode and put a condition if attribute data-column same with value in column_hide I added down class and here is my error screenshot

enter image description here

<div class="pull-right">
<button style="font-size:7pt" class="toggle-vis <?= ($value==0 ? "" : "") ?>" data-column="0">PARTS NO</button>
<button style="font-size:7pt" class="toggle-vis" data-column="1">REVISED NO</button>
<button style="font-size:7pt" class="toggle-vis" data-column="2">LATEST NO</button>
<button style="font-size:7pt" class="toggle-vis" data-column="3">DESCRIPTION</button>
<button style="font-size:7pt" class="toggle-vis" data-column="4">IN FIFO</button>
<button style="font-size:7pt" class="toggle-vis" data-column="8">TOTAL QTY</button>
<button style="font-size:7pt" class="toggle-vis" data-column="9">STOCK J</button>
<button style="font-size:7pt" class="toggle-vis" data-column="10">STOCK B</button>
<button style="font-size:7pt" class="toggle-vis" data-column="11">STOCK S</button>
<button style="font-size:7pt" class="toggle-vis" data-column="12">STOCK X</button>
<button style="font-size:7pt" class="toggle-vis" data-column="13">STORAGE</button>
<button style="font-size:7pt" class="toggle-vis" data-column="14">LAST OPNAME</button>
<button style="font-size:7pt" class="toggle-vis" data-column="15">DISCONTINUED</button>
<button style="font-size:7pt" class="toggle-vis" data-column="16">MESIN</button>
<button style="font-size:7pt" class="toggle-vis" data-column="17">SRP PRICE</button>
<button style="font-size:7pt" class="toggle-vis" data-column="18">SRP COD</button>
<button style="font-size:7pt" class="toggle-vis" data-column="20">MANAGER</button>
<button style="font-size:7pt" class="toggle-vis" data-column="21">DIRECTOR</button>
<button style="font-size:7pt" class="toggle-vis" data-column="22">NOTE</button>

6
  • are these values coming from database? Commented Sep 18, 2018 at 6:08
  • @Alex yes , here data in database 0,1 Commented Sep 18, 2018 at 6:08
  • right but each has its own value, so 0 OR 1 right? what does the table structure look like? does it contain the name e.g. STOCK X and the column id e.g. 12 and the column hide as well? Commented Sep 18, 2018 at 6:09
  • @Alex no, it can be filled 0,1,2,3 till 22 and if the value same with data-column attribut i want add class downs Commented Sep 18, 2018 at 6:11
  • strange schema. you should have made this all 1 table with columns column_name (varchar 50), column_id (int), and hidden (bool). then you could generate this all with a simple foreach. that is what i suggest doing. storing multi purpose string data/serialized data is never a good idea Commented Sep 18, 2018 at 6:13

1 Answer 1

1

Two ways of doing it. Example:

<?php

$string = '0,1,3';

$array = explode(',', $string);

// METHOD 1
// better performance

$flip = array_flip($array); // only have to do this once

if (isset($flip[3])) {
    echo 'true';
}

// OR

// METHOD 2
// probably less efficient

if (in_array(3, $array)) {
    echo 'true';
}

Of course the if logic has to be repeated per "column". The number, in this example 3, will have to be hard coded per each button.

Still suggest making a table like I said in the comments.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.