Jump to content

Adding PHP to JS


divinedesigns1
 Share

Recommended Posts

hey i was wondering if it is possible to add php scripts within javascript codes say i want to add the name of a table in the db into the js that obtain the id in js to make the script work, can i do <?php echo $w3c['js']; ?> and in the html or php echo i placed give the id the js row name, would this work? it should work right?

Link to comment
Share on other sites

If you use XMLHttpRequest (a.k.a. AJAX), it should.
umm i dont know how to use ajax either
Link to comment
Share on other sites

Cara da uma olhada nesse link, ele mostra como passar um array PHP para o javascript e depois devolve-lo para PHPhttp://ahaprogramando.wordpress.com/2008/11/29/passar-array-de-php-para-javascript-e-de-javascript-para-php/sobre como recuperar o banco de dados e usar no javascript tenta isso<?$sql = "SELECT codigo FROM tab_teste "; $res = mysql_query($sql);while ($row = mysql_fetch_array($res)) { $codigo[] = $row['codigo'];}$string_arr_conjunto = implode("|", $arr_conjuntos);?><script>var codigo = [<?php echo $codigo; ?>];var array_codigo = codigo.split("|");alert(array_codigo);</script>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...