• Hello, I’m having problem passing PHP variable to javascript(Rawjs).

    I’ve successfully got data from Mysql and display in HTML .

    But my main goal is to assign the data to js variable. Computed like this

    Rawjs

    [wbcr_php_snippet id="8091"]
    <script>
    var b="[wbcr_php_snippet id="8101"]";
    </script>

    wbcr_php_snippet id=”8091″]

    $query= "select meta_value from wp_gf_entry_meta where meta_key=38";
    
    if ($result = mysqli_query($conn, $query)) {
    
        while ($row = mysqli_fetch_array($result)) {
            $getii = $row[0];      
        }
      mysqli_free_result($result);
    }

    [wbcr_php_snippet id=”8101″]
    echo $getii;

    Have done a lot of research but cant figure out why var b in Rawjs always get 0

    • This topic was modified 7 years, 5 months ago by world2026.
    • This topic was modified 7 years, 5 months ago by world2026.
Viewing 1 replies (of 1 total)
  • Plugin Author webcraftic

    (@webcraftic)

    Hi,

    You can use js code directly inside the snippet.

    See example:

    $query= "select meta_value from wp_gf_entry_meta where meta_key=38";
    
    if ($result = mysqli_query($conn, $query)) {
    
        while ($row = mysqli_fetch_array($result)) {
            $getii = $row[0];      
        }
      mysqli_free_result($result);
    }
    ?>
    <script>
    var b="<?=$getii?>";
    </script>

    Please check your php code so that the $getii variable has the value you need.

    If you are trying to use the shortcode in double-quotes, this can cause problems. You need to escape double quotes inside the shortcode so that you have no problem with that.

    Best regards, Alex

Viewing 1 replies (of 1 total)

The topic ‘‘Insert php, can’t pass its variable to Rawjs’ is closed to new replies.