5

we are using below script to display results for both types : admin & 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 "Designer" column only for type = admin so we are trying to display javascript result with 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 displaying like below image. this code is reason for displaying below image echo "<script>"; when i used echo "display"; still its displaying nothing....

enter image description here

I am new to coding & i tried lot before posting question.

Community
  • 1
  • 1
  • have you include javascript on your project? – Rafael Shkembi Dec 05 '16 at 13:33
  • @RafaelShkembi yes i included `javascript` code also in orders.php file..... –  Dec 05 '16 at 13:35
  • use ` Lots of stuff here Lots of stuff here ` this is best for readability – ixpl0 Dec 05 '16 at 13:36
  • @iXplo thanks for suggestion, sure, i will edit question for better readability..... –  Dec 05 '16 at 13:38
  • 1
    I think your piece of code should work. And the output I see is not what you output. That output might come from some different place. – Seb Dec 05 '16 at 13:48
  • Does it maybe have to do with the **double-quotes** around "Designer" ? – kscherrer Dec 05 '16 at 14:26
  • @Cashbee that's not the issue, i updated the question with proper quotes..... –  Dec 06 '16 at 06:01
  • @Seb you are right, the result is coming just because of this line `echo " –  Dec 06 '16 at 06:30
  • I think that problem is not in part of code you show us. It's looks like you forgot to close `quote` or wrote 2 single quotes before `null` from picture or somewhere else. Show me full php – ixpl0 Dec 06 '16 at 08:05
  • 1
    @iXplo please check full code here : http://pastebin.com/iUXuZAPy –  Dec 06 '16 at 09:02
  • look at `255` line. try to make it in ONE LINE: `var __TEST_DATA__=eval('');` join 255 and 256 lines – ixpl0 Dec 06 '16 at 09:20
  • @iXplo i did that, still same issue..... –  Dec 06 '16 at 09:22
  • and... why do U use `eval()` method in js if you can make any js code without `eval`? – ixpl0 Dec 06 '16 at 09:34
  • Maybe the problem is in that instrument, which minificates your code. – ixpl0 Dec 06 '16 at 09:35
  • @iXplo previous developer wrote that code, now i am working on this..... please tell how i can solve issue ? –  Dec 06 '16 at 09:36

2 Answers2

0

We made it. Code review and a little php magic made our job. It was interesting task, ty

ixpl0
  • 748
  • 5
  • 15
-1
$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";
            }
il_raffa
  • 5,090
  • 129
  • 31
  • 36
ekyalo
  • 1