So I am not sure if this can be done, but I want to copy my database to a javascript array so that I can do what appears to be real-time manipulation of the database. I have used PHP to query the database and build a call to the javascript function. As far as I can tell, everything should work, but it seems the javascript function is never run. Let's not waste time with "why?" suffice it to say, this is what I want to do. I am hoping I don't have to learn yet another language/interface to do this since I have spent the last month trying to master javascript in order to achieve the so called "real-time" feel!
Below is the javascript function which is in the head of my webpage:
Here is the PHP code that is in the body of my web page (I have x'd out the connection info):Code:<script> function AddToArray(i,k,v) { AddToArray[i][k]=v; } </script>
Someone told me not to do it, but I am going to say it anyways: "Thanks in Advance!!"Code:$dbc = mysqli_connect('xxx','xxx' ,'xxx', 'xxx'); $query = "SELECT * FROM registrations2013" ; $result = @mysqli_query($dbc, $query) or die("Error: ".mysqli_error($dbc)); echo "connected to database "; $record = $result->fetch_array(MYSQLI_ASSOC); foreach ($record as $key => $value) { echo "<script>AddToArray('".$i."','".$key."','".$value."');</script>"; }


Reply With Quote
PHP runs on server side and Javascript on client side, so there is no direct way to call Javascript from PHP. however you can out put data from PHP in a format that can be handled by Javascript. for example you can output the records in a JSON array.

Bookmarks