www.webdeveloper.com
Results 1 to 2 of 2

Thread: Call js Function from PHP??

Hybrid View

  1. #1
    Join Date
    Oct 2011
    Posts
    5

    Question Call js Function from PHP??

    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:
    Code:
    <script>
    function AddToArray(i,k,v)
    {
    	AddToArray[i][k]=v;
    }
    
    </script>
    Here is the PHP code that is in the body of my web page (I have x'd out the connection info):

    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>";
    				}
    Someone told me not to do it, but I am going to say it anyways: "Thanks in Advance!!"

  2. #2
    Join Date
    Mar 2009
    Posts
    452
    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.

    i did not get the idea what exactly you want to do. if you explain the requirement it will be easy to help

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles