Getting names from db into javascript array?!?!

I’m trying to figure out how to get:

var origGrp = ['James','Bill','Jennifer','Bob','Karen'];

replaced with something like this:

var origGrp = [<? 
			   $sql="SELECT c.new_userid, c.fname, c.lname FROM ".$prefix."_club_users cu
			   		INNER JOIN ".$prefix."_users u ON cu.new_userid = c.new_userid 
					WHERE cu.clubid='$clubid'";
			   $result = mysql_query($sql);
			   $names = array();
			   while($row = mysql_fetch_array($result)){
				   $names[] = "'".$row['fname']." ".$row['lname']."'";
			   }
			   echo implode(", ", $names); ?>];

… but with no luck :frowning:

Please help …

Make an array in php, then use json_encode()

The reason this shouldn’t be in the javascript forum is because you already know exactly what javascript you need. So, your problem is using php to create a string of text that closely resembles the following


var origGrp = ['James','Bill','Jennifer','Bob','Karen'];