PDA

View Full Version : how to put an into array a $row[ad]


che_anj
09-12-2007, 02:37 PM
i have a query like $query="select * from users";

Id like to put in array the result $row[ad], and pass it into a javascript.

example like this code below

var state = '\
CA:AB:Alberta|\
CA:MB:Manitoba|\
CA:AB:Alberta|\
CA:YT:Yukon Territory|\
AU:AAT:Australian Antarctic Territory|\
AU:ACT:Australian Capital Territory|\
AU:NT:Northern Territory|\

how to make the follwing state into a dynamic depending on what is the result of the query.. tnx..

Fumigator
09-12-2007, 04:20 PM
Your definition of "dynamic" may or may not include this technique, but you have the right idea: The query results in PHP are used to create Javascript code.

$query = "SELECT * FROM your_table";
$result = mysql_query($query);
if (!$result) {
die("Query error in $query<br />".mysql_error());
}
echo "<script type=\"text/Javascript\">\n";
echo "var stateArray = new Array();\n";

for ($i = 0; $i < mysql_num_rows($query); $i++) {
$states = mysql_fetch_assoc($result);
echo "stateArray[$i] = '{$states['ad']}';\n";
}
echo "</script>\n";