-2

Is there a way to get the jquery this.val() read into PHP at runtime?

I have a dynamic push of data and need to run a SQL statement that depends on the jquery value of this.val() - so something like

<?php $sql = "select * from table where id = " . this.val(); ?>
Machavity
  • 30,841
  • 27
  • 92
  • 100
need2lease
  • 136
  • 1
  • 2
  • 10
  • What is `this`? – Satpal Mar 08 '17 at 17:57
  • PHP code is executed on the server **before** the HTML and JavaScript is sent to the **browser** where the JavaScript is executed. Please read http://stackoverflow.com/q/13840429/218196 (which also tells you how to solve your problem). – Felix Kling Mar 08 '17 at 18:00
  • Post JS variable to PHP file with ajax and get the variable there with a $_POST request and use it in your query – user3526204 Mar 08 '17 at 18:19

1 Answers1

1

No, becouse PHP can't read user's DOM. You need to make an ajax request to send the data to the server. jquery.ajax

cymruu
  • 2,808
  • 2
  • 11
  • 23