...

View Full Version : Pushing to javascript array in php loop



sirsaula
07-20-2012, 08:49 PM
I am trying to push to the javascript array after looping 200 times through the member array to push every member that matches the department selected description into the javascript array., However it fails


<? $i = 0 ;
while( $i < 200)
{
if ($members[$i]['department'] == $depttts){

echo "<script type='text/javascript'>contacts.push({"NAME":"SirSaula","TITLE":"John","CONTACT":"bab","RESEARCH":"Ph.D."});</script>";
}
else {
$i++;
}
}
?>

DrDOS
07-20-2012, 09:59 PM
<script>
myarray = [];
<?php
for ( $i = 0 ; $i < count($mystyle) ; $i++ )
{
echo "myarray.push('".$mystyle[$i]."');\n";
}
?>
</script>

An example from one of my pages.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum