mysql php array to javascript functions
Posted: Mon Apr 28, 2008 2:10 am
I'd like to be able to push each data cell in a sql query into a php array which I can then call upon in javascript...so something like this...
<?php
mysql_connect("localhost","root","password") or die (mysql_error("COULD NOT CONNECT TO HOST"));
mysql_select_db("database") or die (mysql_error("COULD NOT FIND DATABASE"));
$ids = mysql_query("SELECT * FROM location");
while ($row = mysql_fetch_array($ids, MYSQL_ASSOC)) {
$num1 = $row["firstNum"];
$num2 = $row["secondNum"];
//Here is where I want the array to function correctly.
//Lets say $num1[0] #=> 35
// $num2[0] #=> 10
}
mysql_free_result($ids);
?>
<script>
for(var i = 0; i<100; i++) {
//this is where $lat would matter, i want to push through all the numbers according to what index 'i' is on
document.write("Number <? echo "$lat | $long" ?> is awesome");
}
</script>
Any Suggestions?
Thanks,
- brIcK
<?php
mysql_connect("localhost","root","password") or die (mysql_error("COULD NOT CONNECT TO HOST"));
mysql_select_db("database") or die (mysql_error("COULD NOT FIND DATABASE"));
$ids = mysql_query("SELECT * FROM location");
while ($row = mysql_fetch_array($ids, MYSQL_ASSOC)) {
$num1 = $row["firstNum"];
$num2 = $row["secondNum"];
//Here is where I want the array to function correctly.
//Lets say $num1[0] #=> 35
// $num2[0] #=> 10
}
mysql_free_result($ids);
?>
<script>
for(var i = 0; i<100; i++) {
//this is where $lat would matter, i want to push through all the numbers according to what index 'i' is on
document.write("Number <? echo "$lat | $long" ?> is awesome");
}
</script>
Any Suggestions?
Thanks,
- brIcK