how can we assign a javascript array from mysql database with the help of php?
<p>I would like to know if we can select data from the database using php and assign it to a javascript array? 
if so what would be the syntax?</p>

<p>I wrote the code below but it is not working</p>

<pre><code>$js_array = "[";
$result = mysql_query("SELECT item_name FROM tbl_item");
while( $row=mysql_fetch_array($result, MYSQL_NUM) ) {
    $js_array .= $row[0]; 
    $js_array .= ",";
}
$js_array{ strlen($js_array)-1 } = ']';

 ?&gt;

&lt;script&gt;
var cities = &lt;?php echo  $js_array; ?&gt;
for(var i=0; i&lt;4;i++)
alert(cities.length);

&lt;/script&gt; 
</code></pre>
