How to pass values from a PHP loop a to jQuery function

Hello guy,

I need help. I can’t figure out how to pass these values from a PHP loop to a jQuery function.
PHP: the playlist, psychically visual


if ($result = $mysqli->query("SELECT mp3_id, genre, mp3_title, mp3_path, mp3_duration FROM mp3 WHERE genre = 'pop' ORDER BY mp3_id DESC LIMIT 5")) {
	while(($row = $result->fetch_object()) && ($i <= 5)) {
		echo "<li>";
		echo "<div id=mp3Item>";
		echo "<div id=mp3Track>";
		echo $i++;
		echo "</div>";
		echo "<div id=mp3Title>";
		echo $row->mp3_title;
		echo "</div>";
		echo "<div id=mp3Lenght>";
		echo $row->mp3_duration;
		echo "</div>";
		echo "</div>";
		echo "</li>";

		$mp3_files = $row->mp3_path;
	}
}

Javascript (An example that works fine with manually added items, I can’t figure out how to pass values from a PHP loop yet):


tracks = [
	{"track":1,"name":"One More Night","length":"04:55","file":"01_One More Night.mp3"},
	{"track":2,"name":"Some Nights","length":"03:37","file":"02_Some Nights.mp3"},
	{"track":3,"name":"We Are Never Ever Getting Back Together","length":"04:05","file":"03_We Are Never Ever Getting Back Togethe.mp3"},
	{"track":4,"name":"Too Close","length":"06:40","file":"04_Too Close.mp3"},
	{"track":5,"name":"Die Young","length":"05:59","file":"05_Die Young.mp3"}
],

I want something like this:


tracks = [
	{"track":1,"name":"$row->mp3_title","length":"$row->mp3_duration","file":"$row->mp3_path"},
	{"track":2,"name":"$row->mp3_title","length":"$row->mp3_duration","file":"$row->mp3_path"},
	.
	.
	.
],

Any suggestion would be greatly appreciated.
Thanks

Aha!

found this: http://stackoverflow.com/questions/12531993/apply-php-mysql-while-loop-in-javascript-object

and this is very helpful: http://php.net/manual/en/function.json-encode.php