Note that there are some explanatory texts on larger screens.

plurals
  1. POmysql query to js...and storing the result in var
    text
    copied!<p>I am getting data from db using mysql query. This data will be used in js functions the following way:</p> <p>page of db query :</p> <pre><code>&lt;?php $server = "localhost"; // MySql host name $username = "root"; // MySQL username $password = ""; // MySQL password $dbname = "admins"; // MySQL database name $table = "usersvisit"; // MySql table name $db=mysql_connect($server,$username,$password) or die(mysql_error()); mysql_select_db($dbname) or die(mysql_error()); $results=mysql_query("SELECT * FROM $table LIMIT 30") or die(mysql_error()); $data="["; while($row=mysql_fetch_assoc($results)) { $data.= "'".$row['idUser']."',"; } $data.="];"; echo $data; ?&gt; </code></pre> <p>Then in the HTML page I want to declare the retrieved data to a variable called origins, so the var origins must store $data to use it later in the other js functions:</p> <pre><code>function createRequest() { var xmlhttp = false; try {xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}catch(E){xmlhttp = false;}} if(!xmlhttp &amp;&amp; typeof XMLHttpRequest!='undefined'){try{xmlhttp = new XMLHttpRequest();}catch(e){xmlhttp=false;}} if(!xmlhttp &amp;&amp; window.createRequest){try{xmlhttp = window.createRequest();}catch(e){xmlhttp=false;}} return xmlhttp; } window.onload=createRequest; // Make an xmlHttpRequest to query_database.php function request_database_query() { var url = "query_database.php"; var con=createRequest(); con.open("GET",url,true); con.onreadystatechange=function() { if(con.readyState==4 &amp;&amp; con.status==200) { document.getElementById("div2").innerHTML=con.responseText; } } con.send(null); } window.onload=request_database_query; var origins= ... // in this var i want to store the data to be as the followling /*var origins = [ 'Euston', 'Kings Cross', 'Liverpool St', 'Paddington', 'St. Pancras', 'Victoria', 'Waterloo' ];*/ </code></pre> <p>Any suggestions?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload