0

Here I need in some way to concatenate my js variable num with php query if it's possible?

Because, I have two select tags (in my html page) the second one depends from the first one. On blur I can get the value of the first, but I don't know how to concatenate this value to the php query which needs to load the second select.

<?php
    echo "<script>";
    echo "var num = 5;";
    $query2="SELECT * FROM region WHERE IDNation=";
    echo "</script>";   
        $res2 = mysqli_query($con,$query2); 
?>
tshepang
  • 12,111
  • 21
  • 91
  • 136
  • You can't do it like this. If you want a `javascript` variable on server side then send it over via AJAX once the page is loaded. – Bilal Budhani May 23 '14 at 11:15

1 Answers1

-1

Basically php is server side language. You can assign any value to php variable during page loading. Javascript works on the user's computer, PHP works on your server. In order to send variables from JS to PHP and vice versa, you need communication such as a page load.

2nd option is you can use cookies

1) First add a cookie jquery plugin.

2) Then store that window width in a cookie variable.

3) Access your cookie in PHP like $_COOKIE['variable name'].(http://www.w3schools.com/php/php_cookies.asp)

M Uzair Qadeer
  • 482
  • 1
  • 8
  • 19