I want to output a value in PHP, something like the example below. How can I achieve this?
var number='1';
var $user_link = "<?php echo bp_core_get_user_domain('" + number + "') ?>";
1 Answer 1
There are a couple-three ways of going about this:
(1) Use an event driven Ajax call that passes the value of the variable number to a PHP script, returning JSON, which is then embedded into the page using JavaScript and the DOM.
(2)Submit the page to the server, passing the value of the variable number as a parameter in a GET query string or a hidden input in a POST.
(3)Take the functionality of bp_core_get_user_domain and put it into a JS function, and forget PHP altogether, unless you're using a PHP global variable to do something. In which case you can just put that data into a cookie on the original page request and let JavaScript read it without having to resubmit the page.
numberbut need to use it as a variable on next line. Maybe you need to use a php variable instead? If you already have it as php variable, use it within php function