I want to copy a PHP array into javascript array. The javascript is being used in the PHP file. It is echoed in the PHP code so when i tried to create a new array in javascripy and just assign the PHP array onto it, it was giving me an error. Array to string conversion. Could some one help me with this.
mysql_select_db("cerebra", $con);
$sql="select name from details order by download desc limit 20";
if (!mysql_query($sql,$con))`enter code here`
{
die('Error: ' . mysql_error());
}
$query=mysql_query($sql,$con);
$names=array();
while($row=mysql_fetch_array($query))
{
$names[]=$row[0];
}
Here $names is the array i want to use in javascript
then i echo my javascript inside the php code itself..:
function makeRequest() {
var d = document.getElementsByName(\"d\")[0].value;
var request = gapi.client.drive.files.list();
var newnames = new Array();
newnames=$names;
request.execute(function(resp)
{
for (i=0; i<resp.items.length; i++) {
var titulo = resp.items[i].title;
var fechaUpd = resp.items[i].modifiedDate;
var userUpd = resp.items[i].lastModifyingUserName;
var userEmbed = resp.items[i].embedLink;
var userAltLink = resp.items[i].alternateLink;
var download = resp.items[i].webContentLink;
var hold=\"Download\";
var flag=0;
<!-- var fileInfo = document.createElement('li');
<!-- fileInfo.appendChild(document.createTextNode('TITLE: ' + titulo + ' - LAST MODIF: ' + fechaUpd + ' - BY: ' + userUpd +' url: ' + hold.link(download)));
<!-- document.getElementById('content').appendChild(fileInfo);
<!--for (var i=0;i<newnames.length;i++){
<!-- if(newnames[i].toString() == titulo){
document.write(titulo + \" \");
document.write(hold.link(download) + \"<br>\");
<!--flag=1;
<!-- }
<!--}
}
<!--if(flag!=1){
<!--document.write(\"not found!\");
<!--}
});
}
Here in the javascript i am trying to convert the php array into javascript array but its not working