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
mysql php array to javascript functions
Moderator: General Moderators
- andym01480
- Forum Contributor
- Posts: 390
- Joined: Wed Apr 19, 2006 5:01 pm
Re: mysql php array to javascript functions
Code: Select all
<script>
for(var i = 0; i<100; i++) {
<?php
mysql_connect("localhost","root","password") or die (mysql_error());
mysql_select_db("database") or die (mysql_error());
$ids = mysql_query("SELECT * FROM location") OR DIE(mysql_error());
while ($row = mysql_fetch_array($ids)) {
echo "document.write(\"Number {$row[0]} | {$row[1]} is awesome\");"; //might need an \ before first ; try it
}
mysql_free_result($ids);
?>
}
</script>