Morning people,

I'm trying to embid php in javascript function and pass the information php read to a separate javascript page using js function

<script type="text/javascript" language="javascript">
	function alerting()
		//var getinformation = new Array(40);
	var information += <?php $sql = $conn->query("select valgroup_id,valgroup_desc from validating_group LIMIT 1"); 
							if(mysql_num_rows($sql) > 0)
								while($rec = $conn->fetchArray($sql))
									$id = $rec['valgroup_id']; 
									$desc = $rec['valgroup_desc'];
									//echo $id;
	document.write(information+"  :sizwe ");
	// return information;

Thank you in advince.

7 Years
Discussion Span
Last Post by Airshow

It depends on exactly what you are trying to do?

As written the PHP code will execute once before the page is served. It will dynamically add to your javascript variable information . This will be fine (when debugged) if that's what you want.

What it WON'T do is run the PHP code each time the javascript function alerting() is called. If this is the functionality you want then you have to learn AJAX, for which there are plenty of tutorials on the web.


This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.