populating javascript array with mysq data
Posted: Mon Feb 28, 2011 3:47 pm
Hi everyone,
I have mysql databse and I wish to populate the data into javascript array, I have tried the follwoing but it is not working, please share your insights:
let me know where i went wrong.
Thanks!!
I have mysql databse and I wish to populate the data into javascript array, I have tried the follwoing but it is not working, please share your insights:
Code: Select all
<html>
<script type="text/javascript" charset="utf-8">
var First = [];
<?php
$host = "localhost"; $user = "root"; $pass = ""; $db = "mydb";
// open connection
$con = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
for($i = 1;$i<=1000;$i++)
{
$query = "SELECT * FROM question WHERE id = $i" ;
// execute query
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
$row = mysql_fetch_row($result);
[u]print"First[<?$i?>] = <? $row[1] ?>"; // HERE I TRY TO POPULATE THE ARRAY[/u]
}
mysql_free_result($result);
// close connection
mysql_close($con);
?>
</script>
</html>Thanks!!