Search code examples
phpjqueryvariablessessiontablesorter

How to format a session variable in a bracket part


I use tablesorter. in the page before i set a session cookie.

tablesorter has this part:

   $.tablesorter.setFilters( table, ['', 'test'  ], true);

now i need the session variable where the word 'test' is, but i don't know how to format it...

is it like this:

  $.tablesorter.setFilters( table, ['', ($_SESSION["favcoloor"]) ], true);

or like this:

 $.tablesorter.setFilters( table, ['', '($_SESSION["favcoloor"])' ], true);

or like this:

  $.tablesorter.setFilters( table, ['', $_SESSION["favcoloor"] ], true);

or

  $.tablesorter.setFilters( table, ['', "$_SESSION["favcoloor"]" ], true);

i can not get it to work, please help me with the correct formatting.


Solution

  • You need to echo the session variable from PHP into your jQuery code :)

    $.tablesorter.setFilters( table, ['', '<?php echo $_SESSION["favcoloor"]; ?>' ], true);
    

    If PHP shorthand tags are enabled, you can use this:

    $.tablesorter.setFilters( table, ['', '<?=$_SESSION["favcoloor"];?>' ], true);