Display javascript result with php if condition

we use below script to display results for both types : admin and designer

script

var colsOption = [ {id: 'entity_id' , header: "Order Id" , width :"15",renderer : my_renderId}, {id: 'created_at' , header: "Order Date" , width :"120"}, {id: 'entity_id' , header: "Order Id" , width :"75"}, {id: 'product_id' , header: "Product Id" , width :"70"}, {id: 'designer_id' , header: "Designer" , width :"110"}, ]; 

enter image description here

now we want to display the "Designer" column only for type = admin , so we are trying to display the javascript result with the php if condition, as mentioned here

Php

 if ($accountType == "admin"){ echo "<script>"; echo "var colsOption = [ {id: 'entity_id' , header: 'Order Id' , width :'15',renderer : my_renderId}, {id: 'created_at' , header: 'Order Date' , width :'120'}, {id: 'entity_id' , header: 'Order Id' , width :'75'}, {id: 'product_id' , header: 'Product Id' , width :'70'}, {id: 'designer_id' , header: 'Designer' , width :'110'} ];"; echo "</script>"; } else { echo "<script>"; echo "var colsOption = [ {id: 'entity_id' , header: 'Order Id' , width :'15',renderer : my_renderId}, {id: 'created_at' , header: 'Order Date' , width :'120'}, {id: 'entity_id' , header: 'Order Id' , width :'75'}, {id: 'product_id' , header: 'Product Id' , width :'70'} ];"; echo "</script>"; } 

but its display as below. this code is the reason for displaying below the image echo "<script>"; when I used echo "display"; while not displaying anything ....

enter image description here

I am new to coding and I tried a lot before posting the question.

+5
source share
3 answers

We did it. The code review and a little php magic did our job. It was an interesting task, ty

0
source
 $accountType = $rows['type']; if ($accountType == "admin") { echo "<script>"; echo "var colsOption = [ {id: 'entity_id' , header: 'Order Id' , width :'15',renderer : my_renderId}, {id: 'created_at' , header: 'Order Date' , width :'120'}, {id: 'entity_id' , header: 'Order Id' , width :'75'}, {id: 'product_id' , header: 'Product Id' , width :'70'}, {id: 'designer_id' , header: "Designer" , width :'110'}, ];"; echo "</script>"; } else { echo "worked"; } 
-1
source

Make sure it works in HTML.

Also, if you do this in JSON, refer to this link: http://php.net/manual/en/function.json-decode.php

-1
source

Source: https://habr.com/ru/post/1260820/


All Articles