I have to create a javascript array whose elements are fetched by php from a database. Is it possible? If so, how?
(I dont want to use ajax to do that)
Answer 1: yes, it can be done.
Answer 2: Here's how:
$js_array = "[";
$result = mysql_query("some query of yours");
while( $row=mysql_fetch_array($result, MYSQL_NUM) ) {
$js_array .= $row[0]; // assuming you just want the first field
// of each row in the array
$js_array .= ",";
}
$js_array{ strlen($js_array)-1 } = ']';
echo "var db_array = $js_array ;";
Cheers!